將DELPHI控制EXCEL文件的函數轉換成DLL動態連接庫,請個位高手,給予指導1小弟在此多謝了(100分)

  • 主题发起人 CHINAJFL
  • 开始时间
C

CHINAJFL

Unregistered / Unconfirmed
GUEST, unregistred user!
library writedll;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
excel2000,variants,comobj,
dialogs,
Classes;

{$R *.res}
function mergeexcelfiles(source:string;destination:string;si,sj,di,dj,osi,osj,odi,odj:integer):integer;stdcall;
var excelapp,excelbook,excelsheet:eek:levariant;
excelapp1,excelbook1,excelsheet1:eek:levariant;
i,j,hs,hd:integer;
tmp,tmp1:string;
exists:boolean;
savedialogs:tsavedialog;
label goout;
begin
try
{ TODO -ojin : 膘蕾珨跺EXCEL妗瞰靡趼峈ㄩEXCELAPP }
excelapp:=createoleobject('excel.application');
excelbook:=excelapp.application;
excelbook.visible:=true;
excelbook.workbooks.open(source);
excelsheet:=excelbook.activesheet;

{ TODO -ojin : 膘蕾鍚俋珨跺EXCEL妗瞰靡趼峈ㄩEXCELAPP1 }
excelapp1:=createoleobject('excel.application');
excelbook1:=excelapp1.application;
excelbook1.visible:=true;
excelbook1.workbooks.open(destination);
excelsheet1:=excelbook1.activesheet;

for i:=di to dj do
begin
for j:=si to sj do
begin
tmp:=excelsheet.cells[j,osi].value;
tmp1:=excelsheet1.cells[i,odi].value;
if (tmp1='') then
goto goout;
if tmp=tmp1 then
begin
hd:=excelsheet1.cells[i,odj].value;
hs:=excelsheet.cells[j,osj].value;
excelsheet.cells[j,osj].value:=hs+hd;
exists:=true;
goto goout;
end;
end;
if not exists then
begin
excelsheet.cells[sj+i,osi].value:=excelsheet1.cells[i,odi].value;
excelsheet.cells[sj+i,osj].value:=excelsheet1.cells[i,odj].value;
end;
goout:
exists:=false;
end;
try
savedialogs:=tsavedialog.Create(nil);
if savedialogs.Execute then
excelbook.activesheet.saveas(savedialogs.FileName);
finally
savedialogs.Free;
end;
result:=1;
excelbook.workbooks.close;
excelbook1.workbooks.close;
excelapp.quit;
excelapp1.quit;
except
result:=0;
end;
end;
exports
mergeexcelfiles;

begin
end.

這個函數的功能是將兩個EXCEL文件合併,條件是指定一個條件列作為比較的依據,然後指定你要相加的列
,符合條件則相加,否則追加到文件中,從而達到合併文件的目的;
如果是作為一個函數使用的話,沒有問題,但是轉換成動態連接庫時候,總是不能通過,由於本人能力
有限,請個位高手給予幫助,多謝1
 
顶部