地震局office自动化软件技术要点分析(2)

来源:互联网 发布:java开发资源库破解版 编辑:程序博客网 时间:2024/04/29 03:44

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)

 

原创粉丝点击