求Delphi访问SQL2000数据库,将某个表数据查询出来/查询结果导出EXCEL
解决方案 »
- 关于跳出过程
- 提示‘>’附近有语支错误,这个语法错在哪?
- dll中调用webservice总是不成功
- Image 控件凹陷问题
- 如何播放一段视频rm格式
- 抛异常问题,请各位高手帮我解决,在线等!!!!!!!!
- MessageBox的问题!!!!!应该是很简单,可是俺不会:(
- 送分,用过Report Machine报表工具的请进。
- 如何检查用户输入的Email合法
- delphi 5.0企业版升级包的序列号!!!急急急!!!
- 报错:cannot create forms. No MDI forms are currently active
- 如何做一个像魔兽里背包那样可以在不同格子里拖动物品(即拖动图片)的功能
思路很简单,把excel当作数据源,两个数据源之间导数据不难吧?
二。用OpenDataSource或者BCP命令直接导出
...ExcelXP,ComObj;//////////////////////////
var
Eclapp,WorkBook:variant;
i,n,s:integer;
xlsFileName:string;
begin
xlsFileName:=extractfilepath(application.ExeName)+'temp.xls'; //导出至本程序目录下
if not cx5.Active then exit;
if cx5.RecordCount<=0 then exit;
if application.MessageBox('确认导出excel表吗?','提示',mb_okcancel+mb_iconinformation)=idcancel then exit;
Eclapp:=createoleobject('Excel.Application');
WorkBook:=CreateOleobject('Excel.Sheet');
workBook:=Eclapp.workbooks.add;
for i:=0 to DBGrid1.FieldCount-1 do
begin
Eclapp.cells[1,i+1]:=dbgrid1.Columns[i].Title.Caption;
end;
cx5.First;
n:=2;
while not cx5.Eof do
for s:=0 to cx5.RecordCount do
begin
eclapp.cells[n,1] :=cx5.Fields[0].AsString;//导出几项加几个
eclapp.cells[n,2] :=''''+cx5.Fields[1].AsString;//文本格式时加''''
inc(n);
cx5.Next;
end;
WorkBook.saveas(xlsFileName);
WorkBook.close;
eclApp.Quit;
eclApp:=Unassigned;
end;
建议换用三方控件,如dbgrideh,cxGrid等等.不但让你现在的需要轻松实现,还有很多你意想不到的功能
使用 dialoge控件con1 .Execute('select * into hjp in "'+'c:\'+'雇员表.xls" "excel 8.0;" from customer');指定固定路径,固定命名
hjp是库名, 中文是文件名,customer表名
con1.Execute ('SELECT company INTO [我爱1Delphi.htm] IN "' + 'c:\' + '" "HTML Export;" FROM CUSTOMER');指定固定路径,固定命名