请大虾帮忙:在word中做好的一个表格,需要向这个表格中的单元格写入数据,不晓得各位有什么好的方法么。
    偶看过了很多的搜索到的帖子,都没有搞清楚,另外如何知道word中表格的某个单元格的坐标?先感谢大家了!

解决方案 »

  1.   

    http://support.microsoft.com/kb/q229310/procedure TForm1.Button1Click(Sender: TObject);
    var
      StrToAdd : String;
      wrdSelection, wrdMailMerge, wrdMergeFields : Variant;
    begin
      // Create an instance of Word and make it visible
      wrdApp := CreateOleObject('Word.Application');
      wrdApp.Visible := True;
      // Create a new document
      wrdDoc := wrdApp.Documents.Add();
      wrdDoc.Select;  wrdSelection := wrdApp.Selection;
      wrdMailMerge := wrdDoc.MailMerge;  // Create MailMerge data file
      CreateMailMergeDataFile;
      // Create a string and insert it into the document
      StrToAdd := 'State University' + Chr(13) +
                  'Electrical Engineering Department';
      wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
      wrdSelection.TypeText(StrToAdd);  InsertLines(4);  // Insert Merge Data
      wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
      wrdMergeFields := wrdMailMerge.Fields;  wrdMergeFields.Add(wrdSelection.Range,'FirstName');
      wrdSelection.TypeText(' ');
      wrdMergeFields.Add(wrdSelection.Range,'LastName');
      wrdSelection.TypeParagraph;
      wrdMergeFields.Add(wrdSelection.Range,'Address');
      wrdSelection.TypeParagraph;
      wrdMergeFields.Add(wrdSelection.Range,'CityStateZip');  InsertLines(2);  // Right justify the line and insert a date field with
      // the current date
      wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphRight;
      wrdSelection.InsertDateTime('dddd, MMMM dd, yyyy',False);  InsertLines(2);  // Justify the rest of the document
      wrdSelection.ParagraphFormat.Alignment := wdAlignParagraphJustify;  wrdSelection.TypeText('Dear ');
      wrdMergeFields.Add(wrdSelection.Range,'FirstName');  wrdSelection.TypeText(',');
      

  2.   


    FWord.ActiveDocument.Tables.Add( 
    Range := FWord.Selection.Range, 
    NumRows := 2, NumColumns := 5, 
    DefaultTableBehavior := wdWord9TableBehavior, 
    AutoFitBehavior := wdAutoFitFixed); 
    FWord.Selection.TypeText(Text:='11'); 
      

  3.   

    FDoc := FWord.Documents.Add; 
    FWord.ActiveDocument.Tables.Add( 
    Range := FWord.Selection.Range, 
    NumRows := 2, NumColumns := 5, 
    DefaultTableBehavior := wdWord9TableBehavior, 
    AutoFitBehavior := wdAutoFitFixed); 
    FWord.Selection.TypeText(Text := '11'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '12'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '13'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '14'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '15'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '21'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '22'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '23'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '24'); 
    FWord.Selection.MoveRight(unit := wdCell); 
    FWord.Selection.TypeText(Text := '35'); 
    except 
    on e: Exception do 
    ShowMessage(e.Message); 
    end; 
    end; 
      

  4.   

    楼上的朋友,这个方法好像不是对现有的Word文档中的表格进行操作啊,你的这个是生成新的Word文档,并且声称新的表格。
      

  5.   

    给我个E-Mail 给份程序于你  ,呵呵