请帮我看看我这么写的把数据导入已知的模板里哪里有问题

hanger1978 2004-04-03 03:48:32
procedure TForm1.BitBtn1Click(Sender: TObject);
var
xlsFilename :string;
ExcelApp,WorkBook : variant ;
FieldCount : Integer;
sFileName:String;
SaveChanges,Filename: OleVariant;
lLCID,i,j:Integer;
begin
BitBtn1.Enabled := False;
FieldCount := dbgrid1.Columns.Count;
try
ExcelApp := CreateOleObject('Excel.Application');
//WorkBook :=CreateOleObject('Excel.Sheet');
except
Application.MessageBox('您的系统没有安装MicroSoft EXCEL软件,数据不能导出!','错误提示',MB_OK+MB_SystemModal+MB_IconStop);
BitBtn1.Enabled := True;
exit;
end;

if SaveDialog1.Execute then
begin
xlsFilename := SaveDialog1.FileName;
if FileExists(xlsFilename) then
begin
if Application.MessageBox('该文件已经存在,是否覆盖?','确认',MB_ICONQUESTION+MB_YESNO)=IDYES then
DeleteFile(xlsFilename)
else
begin
BitBtn1.Enabled := True;
exit;
end;
end;
end
else
begin
BitBtn1.Enabled := True;
exit;
end;

try
try
ExcelApp:=ExcelApp.WorkBooks.Open( 'C:\aa.xls' );
WorkBook :=ExcelApp.WorkBooks.Add ;
for i:=1 to table1.RecordCount do
begin
for j:=1 to FieldCount do //转化一个记录
begin
ExcelApp.Cells.Item[i+1,j]:=dbgrid1.Fields[j-1].AsString ;
end;
table1.Next ;
end;

try
WorkBook.saveas(xlsFilename);
Application.MessageBox('保存完毕!','提示',MB_OK+MB_SystemModal+MB_IconInformation);
except
Application.MessageBox('保存文件出现异常!','错误提示',MB_OK+MB_SystemModal+MB_IconStop);
end;
except
Application.MessageBox('不能正确操作EXECL文件,可能该文件已经被其他程序占用或系统错误!','错误提示',MB_OK+MB_SystemModal+MB_IconStop);
end;
finally
ExcelApplication1.Quit;
//ExcelWorkbook1.Disconnect;
ExcelApplication1.Disconnect;
end;
end;
...全文
51 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
e5022 2004-04-03
  • 打赏
  • 举报
回复
孩子,记得以后不要在论坛上贴着么长的代码,没人看的下去。至少我就已经受不了了。
jgl1010 2004-04-03
  • 打赏
  • 举报
回复
up

5,939

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧