B
blackczh
Unregistered / Unconfirmed
GUEST, unregistred user!
dbgrid中数据导出到excel,ExcelWorksheet1.Cells.Item[dbgrid1.DataSource.DataSet.RecNo+1,i]有问题 ( 积分: 50 )<br />procedure TForm1.Button1Click(Sender: TObject);
var Temp_Worksheet: _WorkSheet;
i:integer;
begin
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption := '应用程序调用 Microsoft Excel';
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,0));
Temp_Worksheet:=ExcelWorkbook1.
WorkSheets.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,0) as _WorkSheet;
ExcelWorkSheet1.ConnectTo(Temp_WorkSheet);
for i:=0 to dbgrid1.FieldCount-1 do
begin
ExcelWOrkSheet1.Cells.Item[1,i+1]:=dbgrid1.Fields.FieldName;
end;
dbgrid1.DataSource.DataSet.First;
while not dbgrid1.DataSource.DataSet.Eof do
begin
for i:=0 to dbgrid1.DataSource.DataSet.FieldCount -1 do
begin
ExcelWorksheet1.Cells.Item[dbgrid1.DataSource.DataSet.RecNo+1,i]:=dbgrid1.DataSource.DataSet.Fields.Value;
dbgrid1.DataSource.DataSet.Next;
end;
end;
end;
运行到ExcelWorksheet1.Cells.Item[dbgrid1.DataSource.DataSet.RecNo+1,i]:=dbgrid1.DataSource.DataSet.Fields.Value;这句就报错le error 800A03EC.请问是什么意思
var Temp_Worksheet: _WorkSheet;
i:integer;
begin
ExcelApplication1.Connect;
ExcelApplication1.Visible[0]:=True;
ExcelApplication1.Caption := '应用程序调用 Microsoft Excel';
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(EmptyParam,0));
Temp_Worksheet:=ExcelWorkbook1.
WorkSheets.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,0) as _WorkSheet;
ExcelWorkSheet1.ConnectTo(Temp_WorkSheet);
for i:=0 to dbgrid1.FieldCount-1 do
begin
ExcelWOrkSheet1.Cells.Item[1,i+1]:=dbgrid1.Fields.FieldName;
end;
dbgrid1.DataSource.DataSet.First;
while not dbgrid1.DataSource.DataSet.Eof do
begin
for i:=0 to dbgrid1.DataSource.DataSet.FieldCount -1 do
begin
ExcelWorksheet1.Cells.Item[dbgrid1.DataSource.DataSet.RecNo+1,i]:=dbgrid1.DataSource.DataSet.Fields.Value;
dbgrid1.DataSource.DataSet.Next;
end;
end;
end;
运行到ExcelWorksheet1.Cells.Item[dbgrid1.DataSource.DataSet.RecNo+1,i]:=dbgrid1.DataSource.DataSet.Fields.Value;这句就报错le error 800A03EC.请问是什么意思