procedure txxcs.buildxlsfile(strFileName:string);
var
ExcelApp,MyWorkBook:Variant;
i,j:integer;
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
MyWorkBook:=CreateOleobject('Excel.Sheet');
except
application.Messagebox('无法打开Xls文件,请确认已 经安装EXCEL.','',mb_OK+mb_IconStop);
Exit;
end;
MyworkBook:=ExcelApp.workBooks.Add;
MyWorkBook.WorkSheets[1].Cells[1,1].Value:='姓名';
MyWorkBook.WorkSheets[1].Cells[1,2].Value:='贷款帐号';
.......
with ProgressBar1 do
begin
Min := 0;
Max := Table1.RecordCount-1;
Table1.First;
for i := Min to Max do
begin
Position := i;
MyWorkBook.WorkSheets[1].Cells[i+2,1].Value:=table1.fieldbyname('xm').asstring;
MyWorkBook.WorkSheets[1].Cells[i+2,2].Value:=table1.fieldbyname('dkzh').asstring;
.....
Table1.Next;
end;
end;
try
MyWorkBook.saveas(strFileName);
MyWorkBook.close;
application.messagebox('保存成功','正确',mb_ok);
ExcelApp.Quit;
ExcelApp:=Unassigned; //释放VARIANT变量
except //当存为一个已有的文档而又不覆盖时将
MyWorkBook.close; //产生一个例外
application.messagebox('保存失败','错误',mb_ok);
ExcelApp.Quit;
end;
end;
d5+win98 passed;