谁能为我提供一段如何在Delphi中把Query中的数据导到Excel中去的列子?
最好解释的详细点。还有顺便问一下,我想在Edit1KeyPress事件中实现对Query的动态查询,请问Edit1KeyPress中对Query.SQL该怎么写? select * from dict where no like--------后面我就不知道怎么写了
大该意思就是说Edit1KeyPress中的值改变一下就马上进行一下过滤,也不知大家明白我意思了没有。
我在线等待,谢谢!!
最好解释的详细点。还有顺便问一下,我想在Edit1KeyPress事件中实现对Query的动态查询,请问Edit1KeyPress中对Query.SQL该怎么写? select * from dict where no like--------后面我就不知道怎么写了
大该意思就是说Edit1KeyPress中的值改变一下就马上进行一下过滤,也不知大家明白我意思了没有。
我在线等待,谢谢!!
var
XlAPP:Variant;
Sheet1:Variant;
i,j:integer;
curRow:integer;begin
if dbgrid.DataSource.DataSet.RecordCount<1 then exit; try
XlApp:=createoleobject('Excel.Application');
XLApp.Visible:=false;
XLApp.Workbooks.Add(xlWBatWorkSheet);
Sheet1 := XLApp.Workbooks[1].WorkSheets['sheet1']; Sheet1.Columns[1].NumberFormat:='@'; /////////这样的语句是让该列存为文本形式
Sheet1.Columns[3].NumberFormat:='@';///用意在与如果数据为0001,不会保存为1
Sheet1.Columns[4].NumberFormat:='@';
// XLApp.Workbooks.Options.CheckSpellingAsYouType:= False;
// XLApp.Workbooks.Options.CheckGrammarAsYouType:= False;
except
on e:exception do
begin
exit;
end;
end; curRow:=0;
for j:=0 to dbgrid.FieldCount-1 do
begin sheet1.cells[1,curRow+1]:=dbgrid.Columns[j].Title.Caption;
inc(curRow);
end;
dbgrid.DataSource.DataSet.First;
i:=2;
while not dbgrid.DataSource.DataSet.Eof do
begin
curRow:=0;
for j:=0 to dbgrid.Columns.Count-1 do
begin Sheet1.cells[i,curRow+1]:=TRim(dbgrid.Fields[j].DisplayText) ;
inc(curRow);
end;
i:=i+1;
dbgrid.DataSource.DataSet.Next;
end;
XLApp.Visible:=true;
end;
调用:以dbgrid的名字为参数传入procedure Tfmhpview.BitBtn5Click(Sender: TObject);
begin
DbgridSaveToExcel(DBgrid1);
end;
大该意思就是说Edit1KeyPress中的值改变一下就马上进行一下过滤
----------------
直接把edit1.text的值赋到QUERY的参数中吧