我用SERVERS控件操作WORD,已经成功打开了目标文件。
这个文件中有一个表格(30列×5行)
想用wordapplication1.selection.talbes.item(1).cell(2,2).range.txt:='xxxx';的语句向指定位置写数据,遇到了麻烦
为什么明明有一个表格,DELPHI却不能识别呢?
因为我通过showmessage(inttostr(wordapplication1.Selection.tables.Count))取表格数目,运行后,显示为0个!!!!

解决方案 »

  1.   

    这是你要的代码var tempw1,tempw2:OleVariant;
    begin
      tempw1:='D:\doc1.doc';
      tempw2:=EmptyParam;
      try
        wordapplication1.Connect;
      except
        showmessage('Word error!');
      end;
      wordapplication1.Documents.Open(tempw1,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2,tempw2);
      wordapplication1.Selection.WholeStory;//这个地方你要注意一下,我用的是全选,你要根据你要的范围定义selection
      wordapplication1.Selection.Tables.item(1).cell(2,2).range.text:='xxxx';
    end;