边
边城过客
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用的是DELPHI+SQL2000,
把数据库中的表导出为EXCEL文件,每次都是自动生成EXCEL文件,为什么不能写入指定的EXCEL文件,我的源代码如下:
procedure TForm9.Printanjuan(dir:string);
var
nowhangi, jilushu, LCID: integer;
ExcelApp: TExcelApplication;
Excelbook: TExcelWorkbook;
ExcelSheet: TExcelWorksheet;
begin
LCID := LOCALE_USER_DEFAULT;
begin
try
ExcelApp := TExcelApplication.Create(Self);
Excelbook := TExcelWorkbook.Create(Self);
ExcelSheet := TExcelWorksheet.Create(Self);
except
showmessage('对不起,您没有安装Excel 2000!');
Exit;
end;
end;
ExcelApp.Connect;
ExcelApp.Workbooks.Add(null, 0);
Excelbook.ConnectTo(ExcelApp.Workbooks[1]);
ExcelSheet.ConnectTo(Excelbook.Sheets[3] as _WorkSheet);
with DM do
begin
if AQ_sbqktjb.RecordCount > 0 then
begin
nowhangi := 4;
for jilushu := 1 to (AQ_sbqktjb.RecordCount) do
begin
nowhangi := nowhangi + 1;
ExcelSheet.cells.Item[nowhangi, 1].RowHeight := 30;
ExcelSheet.cells.Item[nowhangi, 1].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 1] := AQ_sbqktjb.Fieldbyname('jgjb').AsString;
ExcelSheet.cells.Item[nowhangi, 2].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 2] := AQ_sbqktjb.Fieldbyname('yl').AsString;
ExcelSheet.cells.Item[nowhangi, 3].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 3] := AQ_sbqktjb.Fieldbyname('yl01').AsString;;
ExcelSheet.cells.Item[nowhangi, 4].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 4] := AQ_sbqktjb.Fieldbyname('sy').AsString;;
ExcelSheet.cells.Item[nowhangi, 5].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 5] := AQ_sbqktjb.Fieldbyname('gs').AsString;
ExcelSheet.cells.Item[nowhangi, 6].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 6] := AQ_sbqktjb.Fieldbyname('sy01').AsString;;
ExcelSheet.cells.Item[nowhangi, 7].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 7] := AQ_sbqktjb.Fieldbyname('gjj').AsString;;
AQ_sbqktjb.Next;
end;
end;
end;
with DM do
begin
AQ_sbqktjb.First;
end;
Excelbook.SaveCopyAs(dir);
ExcelApp.DisplayAlerts[LCID] := False;
ExcelApp.Quit;
ExcelSheet.Disconnect;
Excelbook.Disconnect;
ExcelApp.Disconnect;
FreeAndNil(Excelbook);
FreeAndNil(ExcelSheet);
FreeAndNil(ExcelApp);
end;
请高手们帮我看看, 怎么才能实现写入指定的EXCEL文件的SHEET中的具体行。
把数据库中的表导出为EXCEL文件,每次都是自动生成EXCEL文件,为什么不能写入指定的EXCEL文件,我的源代码如下:
procedure TForm9.Printanjuan(dir:string);
var
nowhangi, jilushu, LCID: integer;
ExcelApp: TExcelApplication;
Excelbook: TExcelWorkbook;
ExcelSheet: TExcelWorksheet;
begin
LCID := LOCALE_USER_DEFAULT;
begin
try
ExcelApp := TExcelApplication.Create(Self);
Excelbook := TExcelWorkbook.Create(Self);
ExcelSheet := TExcelWorksheet.Create(Self);
except
showmessage('对不起,您没有安装Excel 2000!');
Exit;
end;
end;
ExcelApp.Connect;
ExcelApp.Workbooks.Add(null, 0);
Excelbook.ConnectTo(ExcelApp.Workbooks[1]);
ExcelSheet.ConnectTo(Excelbook.Sheets[3] as _WorkSheet);
with DM do
begin
if AQ_sbqktjb.RecordCount > 0 then
begin
nowhangi := 4;
for jilushu := 1 to (AQ_sbqktjb.RecordCount) do
begin
nowhangi := nowhangi + 1;
ExcelSheet.cells.Item[nowhangi, 1].RowHeight := 30;
ExcelSheet.cells.Item[nowhangi, 1].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 1] := AQ_sbqktjb.Fieldbyname('jgjb').AsString;
ExcelSheet.cells.Item[nowhangi, 2].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 2] := AQ_sbqktjb.Fieldbyname('yl').AsString;
ExcelSheet.cells.Item[nowhangi, 3].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 3] := AQ_sbqktjb.Fieldbyname('yl01').AsString;;
ExcelSheet.cells.Item[nowhangi, 4].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 4] := AQ_sbqktjb.Fieldbyname('sy').AsString;;
ExcelSheet.cells.Item[nowhangi, 5].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 5] := AQ_sbqktjb.Fieldbyname('gs').AsString;
ExcelSheet.cells.Item[nowhangi, 6].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 6] := AQ_sbqktjb.Fieldbyname('sy01').AsString;;
ExcelSheet.cells.Item[nowhangi, 7].WrapText := True;
ExcelSheet.cells.Item[nowhangi, 7] := AQ_sbqktjb.Fieldbyname('gjj').AsString;;
AQ_sbqktjb.Next;
end;
end;
end;
with DM do
begin
AQ_sbqktjb.First;
end;
Excelbook.SaveCopyAs(dir);
ExcelApp.DisplayAlerts[LCID] := False;
ExcelApp.Quit;
ExcelSheet.Disconnect;
Excelbook.Disconnect;
ExcelApp.Disconnect;
FreeAndNil(Excelbook);
FreeAndNil(ExcelSheet);
FreeAndNil(ExcelApp);
end;
请高手们帮我看看, 怎么才能实现写入指定的EXCEL文件的SHEET中的具体行。