我用delphi7查询出一个报表,用DBGrid显示出来,我想把此表的内容保存为Excel的格式,怎么才能导出去啊???
谢谢!!!!!!!非常谢谢大哥大姐们指点一下啊!!!!
谢谢!!!!!!!非常谢谢大哥大姐们指点一下啊!!!!
解决方案 »
- WinINet怎样进行HTTP上传、下载文件
- TreeView1清空我选中的节点下面的所有内
- 有关TServerSocket和TClientSocket的问题
- 导出到EXECL的代码,在D6的东西在D7不能编译,,奇怪。。。
- 通过无线上网卡访问数据库的一些问题
- 判断输入重复应该放在客户端还是应用服务器中??
- 到底MSSQLSERVER里何种类型的字段才能表示BOOLEAN型,并能在WWDBGRID里的复选框里表现出来?
- 大侠,我使用dll中的MDI子窗体,为什么会出错。
- 求ole对象方式调用 word 2007 保存为兼容word97-word2003文件的方法。
- 哪里有可以打印Panel上所有控件的控件呀?
- DLL问题?急急!!
- 请教如何在一个delphi的dll界面中调用另一个dll界面
exit; if uppercase(copy(SaveDialog1.FileName,length(SaveDialog1.FileName)-3,4))<>'.XLS' then
SaveDialog1.FileName:=SaveDialog1.FileName+'.xls';
path:=SaveDialog1.FileName;
if fileexists(path) then
begin
showmessage('文件已存在,请选择另外的文件名!');
exit;
end; formatPath:=ExtractFileDir(Application.ExeName)+'\format.xls';
if not fileexists(formatPath) then
begin
showmessage('模板文件不存在!');
exit;
end;
try
copyfile(pchar(formatPath),pchar(path),true);
except
Showmessage('创建文件时出错');
exit;
end;
rows:=ListView1.Items.Count; try
excel:=createoleobject('excel.application');
excel.visible:=false;
excel.DisplayAlerts:=False;
except
showmessage('打开Excel出错!');
exit;
end;
try
excel.workbooks.Open(path);
book:=excel.workbooks[1];
sheet:=book.worksheets[1]; rows:=rows-1;
for i:=0 to rows do
begin
item:=ListView1.Items[i];
sheet.cells.item[i+7,2]:=item.Caption;
sheet.cells.item[i+7,3]:=item.SubItems[0];
sheet.cells.item[i+7,4]:=item.SubItems[1];
sheet.cells.item[i+7,5]:=item.SubItems[2];
sheet.cells.item[i+7,6]:=item.SubItems[3];
sheet.cells.item[i+7,7]:=item.SubItems[4];
sheet.cells.item[i+7,9]:=item.SubItems[5];
end;
sheet.Cells.Columns.AutoFit; book.save; ListView1.Items.Clear;
except
ShowMessage('保存出错!');
end;
Showmessage('保存成功!');
excel.quit;
USES DbGridEhImpExp;
if dbgrideh1 <> nil then
begin
if saveDialog1.Execute then
begin
SaveDBGridEhToExportFile(TDBGridEhExportAsXLS,dbgrideh1,savedialog1.filename+'.xls',true);
showmessage('成功导出到'+ savedialog1.filename+'.xls');
end;
end
else
showmessage('没有数据表格可供导出') ;