xp的 Try
ExAp1.Connect;
Except
MessageDlg('Excel may not be installed',
mtError, [mbOk], 0);
Abort;
end;
datamodule1.Table1.Active:=true;
ExAp1.Visible[0]:=True;
ExAp1.Caption:='Excel Application';
try
exap1.Workbooks.Open(extractfilepath(application.ExeName)+'report/Book11.xls',
null,null,null,null,null,null,null,null,null,null,null,null,null,null,0);
//打开指定的EXCEL 文件
except
begin
ExcelApplication1.Disconnect;//出现异常情况时关闭
ExcelApplication1.Quit;
showmessage('请选择EXCEL电子表格!');
exit;
end;
end;
ExlWbk1.ConnectTo(ExAp1.Workbooks[1]);
Exlwsh1.ConnectTo(ExlWbk1.Worksheets[1] as _Worksheet);
row:=10;
datamodule1.Table1.Active:=true;
datamodule1.Table1.First;
for i:=1 to datamodule1.Table1.RecordCountdo
if i <= (datamodule1.Table1.RecordCount div 2) then
begin
ExlWsh1.Cells.Item[row,1] := i;
inc(row);
datamodule1.Table1.next;
end
else
begin
ExlWsh1.Cells.Item[(row-(datamodule1.Table1.RecordCount div 2)),8] := i;
inc(row);
datamodule1.Table1.next;
end;
exlwsh1.SaveAs(extractfilepath(application.ExeName)+'report/'+treeview1.Selected.Parent.Text+'.xls');
end;