X
xf9011
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,oleserver,excel2000,olectnrs,db,dbgrids,dbtables,grids,stdctrls,
extctrls,comctrls, ExcelXP,comobj;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
ExcelApplication1: TExcelApplication;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
asheet:Variant;
i:integer;
begin
ExcelApplication1.Visible[0]:=True;
//显示MS-Excel的运行过程
ExcelApplication1.Workbooks.Add(xlWBATWorksheet,0);
//创建一个WorkBook
asheet:=ExcelApplication1.Workbooks.Item[1];
//获取WorkBook听一页WorkSheet
//将carmanagement.dbf的数据填写入aSheet的Cells两维数组内
i:=1;
with table1 do begin
open;
first;
while not eof do begin
asheet.cells[i,1].Value:=fieldbyname('Dw').AsString;
asheet.cells[i,2].Value:=fieldbyname('Bm').AsString;
asheet.cells[i,3].Value:=fieldbyname('Cph').AsString;
asheet.cells[i,4].Value:=fieldbyname('Cpxh').AsString;
asheet.cells[i,5].Value:=fieldbyname('Ccny').AsString;
asheet.cells[i,6].Value:=fieldbyname('Fdjh').AsString;
asheet.cells[i,7].Value:=fieldbyname('Dph').AsString;
asheet.Cells[i,8].Value:=fieldbyname('Dxqk').AsString;
asheet.cells[i,9].Value:=fieldbyname('Bxqh').AsString;
asheet.cells[i,10].Value:=fieldbyname('Bz').AsString;
end;
end;
asheet.SaveAs('d:/a.xls');
asheet.Application.quit;
end;
编译能通过,但是只要一运行就提示'Method "cells" not supported by automation object.'
请问该如何解决呀?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,oleserver,excel2000,olectnrs,db,dbgrids,dbtables,grids,stdctrls,
extctrls,comctrls, ExcelXP,comobj;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
ExcelApplication1: TExcelApplication;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
asheet:Variant;
i:integer;
begin
ExcelApplication1.Visible[0]:=True;
//显示MS-Excel的运行过程
ExcelApplication1.Workbooks.Add(xlWBATWorksheet,0);
//创建一个WorkBook
asheet:=ExcelApplication1.Workbooks.Item[1];
//获取WorkBook听一页WorkSheet
//将carmanagement.dbf的数据填写入aSheet的Cells两维数组内
i:=1;
with table1 do begin
open;
first;
while not eof do begin
asheet.cells[i,1].Value:=fieldbyname('Dw').AsString;
asheet.cells[i,2].Value:=fieldbyname('Bm').AsString;
asheet.cells[i,3].Value:=fieldbyname('Cph').AsString;
asheet.cells[i,4].Value:=fieldbyname('Cpxh').AsString;
asheet.cells[i,5].Value:=fieldbyname('Ccny').AsString;
asheet.cells[i,6].Value:=fieldbyname('Fdjh').AsString;
asheet.cells[i,7].Value:=fieldbyname('Dph').AsString;
asheet.Cells[i,8].Value:=fieldbyname('Dxqk').AsString;
asheet.cells[i,9].Value:=fieldbyname('Bxqh').AsString;
asheet.cells[i,10].Value:=fieldbyname('Bz').AsString;
end;
end;
asheet.SaveAs('d:/a.xls');
asheet.Application.quit;
end;
编译能通过,但是只要一运行就提示'Method "cells" not supported by automation object.'
请问该如何解决呀?