CreateOleObject 怎么用? (delphi 5),怎么老通不过.. (100分)

  • 主题发起人 主题发起人 jimyho
  • 开始时间 开始时间
J

jimyho

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TfrmContralExecl.cmdOpenExcelClick(Sender: TObject);
var
row, column,i:integer ;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleObject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已经安装 EXCEL.','',mb_OK+mb_IconStop);
Exit;
end;
....

我应该怎样完整的声明它.
 
你要在 uses 中加上 ComObj 才行啊
 
漏了几句:
uses
Excel97

var
ExcelApp,MyWorkBook:OleVariant;

但还是不行.... why?
 
uses comobj;
procedure printpay1;
var
i,j:integer;
typef:smallint;
msexcel:olevariant;
wbook,wsheet:olevariant;
begin
with reportfrm,DataModule1.qry do
begin
Close;
sql.clear;
sql.add('select sccj,cjmc,sum(yfks),sum(yfks-wfks),sum(wfks) from cjfmx group by sccj,cjmc ');
sql.add(' union select 10000,' + '''合计'''+',sum(yfks),sum(ffks),sum(wfks) from cjfmx ');
open;
MsExcel:= CreateOleObject('Excel.Application');
WBook:=MsExcel.Application;
wbook.workbooks.Open(ExtractFileDir(paramstr(0))+'/pay1.xls');//
//*.xls 预先作好
WSheet:=WBook.ActiveSheet;
for i:=1 to recordcount do
begin
for j:=1 to fieldcount do
wsheet.cells[i+1,j].value:=fields[j-1].asstring;
next;
end;
DataModule1.qry.close;
WBook.Visible:= True;
end;
end;

 
接受答案了.
 

Similar threads

I
回复
0
查看
793
import
I
I
回复
0
查看
619
import
I
I
回复
0
查看
558
import
I
I
回复
0
查看
696
import
I
后退
顶部