0

我想使用 Microsoft.Interop.Word 以编程方式打开一个 Word 文档,并将注释插入到表格单元格中。我有单元格范围的开始和结束位置。(范围.开始\范围.结束)

Application.ActiveDocument.Select(); // select ative document
Range rg = Application.Selection.Range; // get the range of the current selection (all document)


 if (rg.Tables.Count > 0)
 {

     Microsoft.Office.Interop.Word.Range rngTab = rg;

     //set the coordinate of the Range of the text 
     rngTab.Start = startRng;
     rngTab.End = endRng;


     doc.ActiveWindow.Visible = true;
     rg.Select();
     Application.ActiveDocument.Comments.Add(rngTab, ref commentText);                                           
  }

当插入评论字崩溃

4

1 回答 1

0

我将您的代码转换为帕斯卡并进行了一些更改。它工作正常,没有错误! 看见

var WApplication:twordapplication; rg,rngTab:range;
commentText:olevariant;
begin
commentText:='123';
WApplication := twordapplication.Create(form1);
WApplication.Connect;
WApplication.Visible:=true;
WApplication.Activate;
rg:= WApplication.Selection.Range; // get the range of the current selection (all document)
rngTab:= rg;
     //set the coordinate of the Range of the text
     rngTab.Start:= 1;
     rngTab.End_:= 2;
     rg.Select();
     WApplication.ActiveDocument.Comments.Add(rngTab, commentText);// add comment to text
     rngtab:=WApplication.ActiveDocument.Tables.Item(1).cell(2,2).range;
     rngtab.Select();
     WApplication.ActiveDocument.Comments.Add(rngTab, commentText); // add comment to cell in the table
end;
于 2015-06-19T07:44:04.873 回答