如何在delphi中向word插入表格及数据?
现在需要向word文档中,插入多张已有固定格式的表格,并在表格中输入数据?

解决方案 »

  1.   

      FWordApp, FWordDoc, FTable: OleVariant;
    ...
      try
        FWordApp := GetActiveOleObject('Word.Application');
      except
        try
          FWordApp  := CreateOleObject('Word.Application');
        except
          //没装Word
          Exit;
        end;
      end;
      FWordDoc := FWordDoc := FWordApp.Documents.Add;
    ...
      //插入表格
      FTable := FWordDoc.Tables.Add(FWordDoc.Range, 1, 1);
      FTable .Cell(1, 1).Range.Text := '表格内容';
    ...
    可看Delphi安装目录下Ocx\Servers下的Word相关单元及Word中的VBA部分
      

  2.   


      FTable.Borders.InsideLineStyle := wdLineStyleSingle;
      FTable.Borders.OutsideLineStyle := wdLineStyleSingle;
      FTable.Borders.InsideColorIndex := wdBlack;
      FTable.Borders.OutsideColorIndex := wdBlack;去Ocx\Servers看那些文件,或者用TWordApplication\TWordDocument等试