- 作者:zhaozj
- 发表时间:2020-12-23 10:59
- 来源:未知
1:把数据中表做成word的表格
delphi代码如下:
procedure TForm1.bbtn1Click(Sender: TObject);var WordApp,WordDoc,WordTable:OleVariant; i,j:integer;begin ADOQuery1.Open; WordApp:= CreateOleObject('Word.Application'); WordApp.Visible:= True; WordDoc:=WordApp.Documents.Add; WordTable:=WordDoc.Tables.Add(WordApp.Selection.Range, ADOQuery1.RecordCount + 1, ADOQuery1.FieldCount);
for i:=1 to ADOQuery1.FieldCount do begin WordTable.Cell(1,i).Range.InsertAfter(ADOQuery1.Fields[i-1].FieldName); end; i:=2; with ADOQuery1 do while not eof do begin for j:=1 to ADOQuery1.Fields.Count do begin WordTable.Cell(i,j).Range.InsertAfter(ADOQuery1.Fields[j-1].Asstring); end; Next; Inc(i); end;end;
其中, ADOQuery1.Open;得sql语句为'Select * from 1_WZ'
运行如下图:
---to be continued by 小榕(Littleroy)