如何把ADOQUERY查询到的结果保存为*.txt *.html 和EXCEL数据格式呢? 用quickreport可以另存为*.txt *.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 保存为excel:unit ExcelTest;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, Buttons, ExtCtrls,db,DBTables, ComCtrls;typeTForm1 = class(TForm)Button1: TButton;Query1: TQuery;procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }procedure WriteDatasetToExcel(AQueryName: TQuery; AStrVar: String);end;varForm1: TForm1;implementationuses Comobj;{$R *.DFM}{ TForm1 }procedure TForm1.WriteDatasetToExcel(AQueryName: TQuery; AStrVar: String);varEclApp,WorkBook : Variant;xlsFileName : String ;I : Integer ;column : Integer ;Row : Integer ;Fdate:TDateTime;Year, Month, Day, Hour, Min, Sec, MSec: Word;StrDate:String ;StrDate1:String ;BeginFdate:=now ;DecodeDate(Fdate, Year, Month, Day);DecodeTime(Fdate, Hour, Min, Sec, MSec);StrDate:=formatdatetime('yyyy-mm-dd-hh-mm-ss',Fdate) ;StrDate1:=formatdatetime('yyyy/mm/dd hh:mm:ss',Fdate) ;If AStrVar='Excel文件测试' ThenBeginxlsfilename :='Excel文件测试' ;End ;TryBeginEclApp := CreateOleObject('Excel.Application');WorkBook:=CreateOleObject('Excel.Sheet');EndExceptShowMessage('您的计算机上没有 Microsoft Excel!');Exit;end;tryworkBook:=EclApp.workBooks.Add ;row:=2;EclApp.Workbooks.Item[1].Activate;eclApp.Cells.font.colorindex:=5 ;EclApp.Activesheet.Cells(1,1):=AStrVar ;For I := 1 To AQueryName.FieldCount DoEclApp.Activesheet.Cells(2,I):=AQueryName.Fields[I-1].FieldName ;If Not AQueryName.Active Then AQueryName.Active := True ;AQueryName.First ;While Not(AQueryName.Eof) dobegincolumn:=1;for i:=1 to AQueryName.FieldCount dobegineclApp.Cells.Item[row+1,column]:=AQueryName.fields[i-1].AsString;column:=column+1;end;AQueryName.Next;row:=row+1;End ;WorkBook.saveas(xlsFileName);WorkBook.close;WorkBook:=eclApp.workBooks.Open(xlsFileName);if MessageDlg('xlsFileName'+'对该文件是否保存?',mtConfirmation,[mbYes, mbNo], 0) = mrYes thenWorkBook.saveElseworkBook.Saved := True;WorkBook.Close;eclApp.Quit;eclApp:=Unassigned;exceptShowMessage('Excel 文件保存失败');WorkBook.close;eclApp.Quit; {释放VARIANT变量}eclApp:=Unassigned;end;ShowMessage('EXCEL 文件保存完毕') ;end;procedure TForm1.Button1Click(Sender: TObject);beginWriteDatasetToExcel(query1,'Excel文件测试');end;end. "用quickreport可以另存为*.txt *.html"谁能详细的说说呢? //这里有一篇DBGrid -> Htmlhttp://www.csdn.net/Expert/TopicView1.asp?id=735262 在CSDN里找一下吧,有很多内容是关于这个的,你在搜索时输入dbgrid就能找出来。:)我就是这样找的。 //参考$(Delphi)\Demos\QuickRpt\Qr3//参考如下语句uses QRExport;procedure TForm1.Button1Click(Sender: TObject);var AExportFilter : TQRHTMLDocumentFilter;begin// TQRHTMLDocumentFilter// TQRAsciiExportFilter// TQRTextFilter AExportFilter := TQRHTMLDocumentFilter.Create('REPORT.HTM'); try QuickRep1.ExportToFilter(AExportFilter) finally AExportFilter.Free; end;end; Drate(小虫) 和kds(生)的方法我试过了,速度有点忙了!也许是机器的问题。不知道有没有更好的方法呢?谢谢大家还有zswang(伴水),我再试试。 一个简单的问题 100分寻求答案!表导出到文本文件,但表中存在图像字段,图像字段值不能导出,请问各位高手数据库中图像怎么导才能导出?能导到什么样的 请问各位,那有TreeView中手工增删结点的范例下载 帮帮忙!小问题!! dbgrid中的序号问题?? 怎样把串直接转换成十六进制的数 初学者的3问题 投票:如果再一次爆发美国侵略朝鲜的战争,中国将参战吗? 请各路高手帮忙! ADO+Parodx 的愚蠢错误,有经验的人一下子就可以挣100分。 如何嵌入OLE对象 看过李维的〈分布式电子商务篇〉的请快来帮帮忙!有分的呦!来的都有分,回答到的是高分!
unit ExcelTest;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls,db,DBTables, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Query1: TQuery;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WriteDatasetToExcel(AQueryName: TQuery; AStrVar: String);
end;var
Form1: TForm1;implementationuses Comobj;{$R *.DFM}{ TForm1 }procedure TForm1.WriteDatasetToExcel(AQueryName: TQuery; AStrVar: String);
var
EclApp,WorkBook : Variant;
xlsFileName : String ;
I : Integer ;
column : Integer ;
Row : Integer ;
Fdate:TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
StrDate:String ;
StrDate1:String ;
Begin
Fdate:=now ;
DecodeDate(Fdate, Year, Month, Day);
DecodeTime(Fdate, Hour, Min, Sec, MSec);
StrDate:=formatdatetime('yyyy-mm-dd-hh-mm-ss',Fdate) ;
StrDate1:=formatdatetime('yyyy/mm/dd hh:mm:ss',Fdate) ;
If AStrVar='Excel文件测试' Then
Begin
xlsfilename :='Excel文件测试' ;
End ;Try
Begin
EclApp := CreateOleObject('Excel.Application');
WorkBook:=CreateOleObject('Excel.Sheet');
End
Except
ShowMessage('您的计算机上没有 Microsoft Excel!');
Exit;
end;
try
workBook:=EclApp.workBooks.Add ;
row:=2;
EclApp.Workbooks.Item[1].Activate;
eclApp.Cells.font.colorindex:=5 ;
EclApp.Activesheet.Cells(1,1):=AStrVar ;
For I := 1 To AQueryName.FieldCount Do
EclApp.Activesheet.Cells(2,I):=AQueryName.Fields[I-1].FieldName ;
If Not AQueryName.Active Then AQueryName.Active := True ;
AQueryName.First ;
While Not(AQueryName.Eof) do
begin
column:=1;
for i:=1 to AQueryName.FieldCount do
begin
eclApp.Cells.Item[row+1,column]:=AQueryName.fields[i-1].AsString;
column:=column+1;
end;
AQueryName.Next;
row:=row+1;
End ;
WorkBook.saveas(xlsFileName);
WorkBook.close;
WorkBook:=eclApp.workBooks.Open(xlsFileName);
if MessageDlg('xlsFileName'+'对该文件是否保存?',
mtConfirmation,[mbYes, mbNo], 0) = mrYes then
WorkBook.save
Else
workBook.Saved := True;
WorkBook.Close;
eclApp.Quit;
eclApp:=Unassigned;
except
ShowMessage('Excel 文件保存失败');
WorkBook.close;
eclApp.Quit; {释放VARIANT变量}
eclApp:=Unassigned;
end;
ShowMessage('EXCEL 文件保存完毕') ;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
WriteDatasetToExcel(query1,'Excel文件测试');
end;end.
http://www.csdn.net/Expert/TopicView1.asp?id=735262
我就是这样找的。
$(Delphi)\Demos\QuickRpt\Qr3//参考如下语句
uses QRExport;procedure TForm1.Button1Click(Sender: TObject);
var
AExportFilter : TQRHTMLDocumentFilter;
begin
// TQRHTMLDocumentFilter
// TQRAsciiExportFilter
// TQRTextFilter
AExportFilter := TQRHTMLDocumentFilter.Create('REPORT.HTM');
try
QuickRep1.ExportToFilter(AExportFilter)
finally
AExportFilter.Free;
end;
end;
。
不知道有没有更好的方法呢?谢谢大家还有zswang(伴水),我再试试。