用Ole Automation,拿着MSDN,你慢慢看吧,里面东西很多。
Delphi里面的TWordDocument可以用。

解决方案 »

  1.   

    http://www.delphibbs.com/delphibbs/dispq.asp?lid=737517
      

  2.   

    可以复杂问题简单化,先用word的宏录制功能录制宏代码,然后翻译成c++语言作为函数调用
    就可以了。我就是这样来控制excel的。
      

  3.   

    举个简单的打开word并制表的程序:
    unit example;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,ComObj, OleServer, Word97, Db, DBTables;type
      TForm1 = class(TForm)    Button1: TButton;
        Query1: TQuery;
        DataSource1: TDataSource;
        Database1: TDatabase;
      procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      v_app: variant;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);var
     v_app:variant;
     v_doc:variant;
     v_ran,tmptable, v_range:variant;
    begin
        v_app:=GetActiveOleObject('Word.Application');
        //v_app:=CreateOleObject('Word.Application');
        v_app.visible:=True;
        v_app.Documents.Add;    v_doc:=v_app.ActiveDocument;
        v_app.Documents.Item(1).Range.ParagraphFormat.Alignment:=1;
        v_app.Documents.Item(1).Range.Text:='.........';
        v_doc:=v_app.Documents.Item(1);
        v_doc.Paragraphs.Add;
        v_ran:=v_doc.Paragraphs.Item(1).Range;
        v_ran.Bold:=1;
        v_ran.Font.Size:=25;
        v_range:=v_doc.Range((v_doc.Paragraphs.Item(v_doc.Paragraphs.Count)).Range.End-1);
    //制表
       tmptable:=v_doc.Tables.Add(v_range,Stu_num*Gro_num+2,Exp_num+Spe_num+2);
       tmptable.Range.Cells.SetWidth(24,'wdAdjustNone');
       tmptable.Range.Cell(3,4).SetWidth(48,'wdAdjustNone');
       tmptable.Rows.Alignment:=1;
       tmptable.Range.Cells.VerticalAlignment:=1;
       tmptable.Range.Font.Size:=12;   tmptable.Cell(2, 1).Merge(tmptable.Cell(1, 1));//合并单元格
           v_doc.Tables.Item(v_doc.Tables.Count).Cell(1,1).Range.InsertAfter('分组');    tmptable.Cell(2,1).Merge(tmptable.Cell(1,2));
            v_doc.Tables.Item(v_doc.Tables.Count).Cell(1,2).Range.InsertAfter('序号');    with Query1 do
        begin
           Close;
           SQL.Clear;
           str:='select * from 某表名';
           SQL.Add(str);
           Open;
           First;    while not Query1.Eof do
        
          begin
            v_doc.Tables.Item(v_doc.Tables.Count).Cell(1,i+2).Range.InsertAfter(Query1.fieldbyname('表头').asstring);
            v_doc.Tables.Item(v_doc.Tables.Count).Cell(2,i).Range.InsertAfter(Query1.fieldbyname('day').asstring);
            v_doc.Tables.Item(v_doc.Tables.Count).Cell(2,i).Range.InsertAfter(Query1.fieldbyname('time').asstring);
          end;
          Query1.Next;
        end;
    end;
    end.
      

  4.   

    Delphi的控件栏Server页里面有很多控件,可以操作Word、Excel等
      

  5.   

    Delphi 4 Unleashed这本书里面有例子。(极力推荐这本经典书!)
      

  6.   

    你用Word的录制宏录一段宏,然后研究一下,并将其转换为delphi代码。OK!!!!