问题:c( 积分:5, 回复:24, 阅读:4023 )
分类:数据库-文件型 ( 版主:hbezwwl, bubble )
来自:nter, 时间:2000-3-21 17:11:00, ID:203496 [显示:小字体 | 大字体]
如何将数据库内容导出到EXCEL
来自:gxg8816, 时间:2000-3-21 17:26:00, ID:203508
ODBC
TBatchMove
来自:wst, 时间:2000-3-30 8:49:00, ID:208128
有具体的例子吗?
来自:lha, 时间:2000-3-30 8:55:00, ID:208141
大概 5 points is too too less.
it's not enough to finish you quession.
来自:jj.begin, 时间:2000-3-30 8:55:00, ID:208142
5分大概只能回答1/10的内容吧??
来自:wst, 时间:2000-3-30 9:53:00, ID:208213
we are all friends,do not to say you and me;
来自:caiaj, 时间:2000-3-30 19:23:00, ID:208647
Delphi 5 Ole Excel
来自:liuchuanbo, 时间:2000-4-1 16:08:00, ID:209930
procedure TForm3.BitBtn2Click(Sender: TObject);
var f:textfile;
fs,str:string;
i,j,k:integer;
begin
if not query1.IsEmpty then
begin
if savedialog1.execute then
begin
fs:=savedialog1.filename;
assignfile(f,fs);
rewrite(f);
for i:=0 to query1.FieldCount-1 do
begin
begin
str:=query1.Fields[i].Displaylabel;
for j:=query1.Fields[i].datasize to 35 do
begin
str:=str+' ';
end;
write(f,str);
end;
end;
writeln(f,'');
query1.first;
for i:=0 to query1.RecordCount-1 do
begin
for j:=0 to query1.FieldCount-1 do
begin
str:=query1.Fields[j].Displaytext;
for k:=query1.Fields[j].datasize to 35 do
begin
str:=str+' ';
end;
write(f,str);
end;
writeln(f,'');
query1.next;
end;
filestr1:=fs;
closefile(f);
end;
end
else
begin
showmessage('empty table');
tindex0
end;
end;
存成excel格式
来自:wjiachun, 时间:2000-8-14 10:50:00, ID:308026
接受答案了.
来自:垦荒牛, 时间:2003-1-23 20:29:00, ID:1596422
procedure TForm1.BitBtn1Click(Sender: TObject);
var
filename:olevariant;
xlsname:string;
i,row,column:integer;
begin
row:=4;
while not (query1.eof) do
begin
column:=1;
for i:=1 to query1.FieldCount do
begin
excelworksheet1.Cells.Item[row,column]:=
query1.Fields[i-1].AsString;
column:=column+1;
end;
query1.Next;
row:=row+1;
end;
inputquery('保存','文件名',xlsname);
excelWorksheet1.SaveAs(xlsname);
excelWorkbook1.Close;
excelapplication1.Disconnect;
excelapplication1.Free;}
//excelapplication1.Quit;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
filename:olevariant;
{xlsname:string;
i,row,column:integer;}
begin
filename:='c:/小修作业日报.xls';
try
excelapplication1.Connect;
except
messagedlg('是否确定安装Excel?',mtError,[mbOK],0);
Abort;
end;
excelapplication1.Visible[0]:=false;
excelapplication1.Caption:='作业日报系统';
excelapplication1.Workbooks.Add(filename,0);
excelWorkbook1.ConnectTo(excelapplication1.Workbooks[1]);
excelworksheet1.ConnectTo(excelWorkbook1.Worksheets[1] as _worksheet);
end;
来自:chenzhou, 时间:2003-3-31 18:54:00, ID:1725799
为什么导出后,
关闭再双击这个 EXCEL 文件时只能看到EXCEL的菜单,看不到EXCEL的内容。
???
来自:jxc163, 时间:2003-4-20 17:52:00, ID:1785644
这个问题为什么没有人解决完呢?
来自:liuziquan, 时间:2003-5-17 11:30:00, ID:1869642
后台EXCEL进程没有关闭!!
来自:mula, 时间:2003-8-1 15:05:00, ID:2076921
在程序里,如何解决这个问题啊?
来自:jxc163, 时间:2003-8-1 17:55:00, ID:2077538
在导出完以后,要断开连接。这样就可以了。.
来自:behine, 时间:2003-10-16 16:19:00, ID:2234611
導出後格式不對,應該如何使數據格式和excel的格式相對應呢?
来自:ken_gj, 时间:2004-4-7 16:22:28, ID:2545226
我也想要一个完整的解决办法。
来自:wzf770202, 时间:2004-9-20 13:23:52, ID:2815528
我這有一過程可以參考:
procedure DataToExcel(TbOrQuery:TCustomADODataset;GridCtrl:TDBGrid );
var
SaveFn:String;
SaveDialog1: TSaveDialog;
ExcelApplication1: TExcelApplication;
ExcelWorksheet1: TExcelWorksheet;
ExcelWorkbook1: TExcelWorkbook;
ACount,i:Integer;
low,row:Integer;
begin
SaveDialog1:=TSaveDialog.Create(Application.Owner);
SaveDialog1.Filter:='*.Xls';
if Not SaveDialog1.Execute then SaveDialog1.Execute ;
SaveFn:=SaveDialog1.FileName ;
if SaveFn='' then begin messagedlg('請輸入文件名!',mtinformation,[mbok],0);
abort end;
low:=2;
ACount:=GridCtrl.FieldCount ;
ExcelApplication1:=TExcelApplication.Create(Application.Owner);
ExcelWorksheet1:=TExcelWorksheet.Create(Application.Owner );
ExcelWorkbook1:=TExcelWorkbook.Create(Application.Owner );
try
ExcelApplication1.Connect ;
except
MessageDlg('請確定是否正確安裝Excel2000?',mterror,[mbok],0);
abort;
end;
ExcelApplication1.Visible[0]:=false;
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Add(null,0) );
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
for i:=1 to ACount do
ExcelWorksheet1.Cells.Item[1,i]:=GridCtrl.Columns[i-1].Title.Caption ;
TbOrQuery.First ;
while not TbOrQuery.Eof do
begin
for row:=1 to ACount do begin
ExcelWorksheet1.Cells.Item[low,row].NumberFormatLocal:='@';
ExcelWorksheet1.Cells.Item[low,row]:=TbOrQuery.Fields[row-1].Value ;
end;
low:=low+1;
TbOrQuery.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveFn+'.xls');
ExcelWOrkBook1.Close(False);
ExcelWorksheet1.Disconnect ;
ExcelWorkbook1.Disconnect ;
ExcelApplication1.Disconnect;
ExcelWOrkBook1.Close;
ExcelApplication1.Quit;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
ExcelApplication1.Free ;
end;
来自:ws5628, 时间:2004-10-7 17:52:34, ID:2837139
begin //xls格式
tmpfile := extractfilepath(application.ExeName) +'s.xls';
(dm.addtable.FieldByName('content4') as Tblobfield).SaveToFile(tmpfile);
try
msworda1 := CreateOleObject('excel.application');
except
Raise Exception.Create('无法打开excel,请确认已安装excel。');
end;
msworda1.WorkBooks.Add(tmpfile);
msworda1.visible := true;
end;
来自:秦琼, 时间:2004-10-18 13:28:42, ID:2852450
通过下面编码可以导出到Excel,但是导出的所有字段都在一列里,请问如何解决此类问题。
procedure TForm3.BitBtn2Click(Sender: TObject);
var f:textfile;
fs,str:string;
i,j,k:integer;
begin
if not query1.IsEmpty then
begin
if savedialog1.execute then
begin
fs:=savedialog1.filename;
assignfile(f,fs);
rewrite(f);
for i:=0 to query1.FieldCount-1 do
begin
begin
str:=query1.Fields[i].Displaylabel;
for j:=query1.Fields[i].datasize to 35 do
begin
str:=str+' ';
end;
write(f,str);
end;
end;
writeln(f,'');
query1.first;
for i:=0 to query1.RecordCount-1 do
begin
for j:=0 to query1.FieldCount-1 do
begin
str:=query1.Fields[j].Displaytext;
for k:=query1.Fields[j].datasize to 35 do
begin
str:=str+' ';
end;
write(f,str);
end;
writeln(f,'');
query1.next;
end;
filestr1:=fs;
closefile(f);
end;
end
else
begin
showmessage('empty table');
tindex0
end;
end;
存成excel格式
来自:stonelgq, 时间:2006-2-4 16:07:54, ID:3344071
各位大虾小弟的做法是这样的:
procedure ImportInfoFromExcel(FileName:String;
exApp:TExcelApplication;
exWBook:TExcelWorkBook;
exWSheet:TExcelWorkSheet;
LV:TbsSkinListView);
var
excelapplication1:TExcelApplication;
excelWorkbook1:TExcelWorkBook;
excelworksheet1:TExcelWorkSheet;
i,j:Integer;
str:String;
Begin
excelapplication1:=exApp;
excelWorkbook1:=exWBook;
excelworksheet1:=exWSheet;
try
excelapplication1.Connect;
except
MyMessage('是否确定安装Excel?');
Abort;
end;
excelapplication1.Visible[0]:=false;
excelapplication1.Caption:='导入公安制证机关提供的数据文件';
excelapplication1.Workbooks.Add(filename,0);
excelWorkbook1.ConnectTo(excelapplication1.Workbooks[1]);
excelworksheet1.ConnectTo(excelWorkbook1.Worksheets[1] as _worksheet);
{第一列:身份证号码
第二列:姓名
第三列:领证方式
第四列:领证人
第五列:邮寄地址
规则 :如果原有此人数据,则覆盖此人数据}
For i:=1 To excelworksheet1.Cells.Row Do
Begin
IF Length(Trim(excelworksheet1.Cells.Item[i,1]))>0 Then
Begin
For j:=1 To 5 Do
Begin
MyMessage(excelworksheet1.Cells.Item[i,j]);
MyMessage(IntToStr(excelworksheet1.Cells.Row));
MyMessage(IntToStr(excelworksheet1.Cells.Column));
End;
End;
End;
excelWorkbook1.Close;
excelapplication1.Disconnect;
excelapplication1.Free;
End;
来自:hnhsh, 时间:2006-2-12 22:06:48, ID:3351563
导出到excel后要在程序里马上直接打开这个文件该怎么做?
来自:gxygxk, 时间:2006-6-30 12:47:12, ID:3492221
我学习后导出没问题,关键导出之后不能正常显示。估计缺代码。不知为什么。
来自:yyh0121, 时间:2006-10-19 17:15:45, ID:3600984
看到这上面问题偶想到dbgrid导出到excel数据时, 包括我自己做的都有一个问题就是比如数据为 00180110531125
且这数据还是字符行的,导出到excel显示为 科学计数法1.801111E+11,
而不能导出显示为原样数据库中的, 00180110531125 而且我要导出就是这个数据;
来自:abin30, 时间:2006-11-30 14:39:05, ID:3635927
判断,如果是文本类型字段 在内容前边加 单引号'
或者,设置单元格格式为文本:
worksheet.cell[x,y].NumberFormatLocal:='@';
同样配合 NumberFormat 可以设置多种格式,一下是VBA 手册上写的
格式化代码与“单元格格式”对话框中“格式化代码”选项相同的字符串。Format 函数使用与 NumberFormat 和 NumberFormatLocal 属性不同的格式化代码。
示例
以下这些示例分别对 Sheet1 中的 A17 单元格、第一行和 C 列的数字格式进行设置。
Worksheets("Sheet1").Range("A17").NumberFormat = "General"
Worksheets("Sheet1").Rows(1).NumberFormat = "hh:mm:ss"
Worksheets("Sheet1").Columns("C"). _
NumberFormat = "$#,##0.00_);[Red]($#,##0.