【问题标题】:Microsoft Interops Word Insert Comment into Table Cell Crash WordMicrosoft Interops Word 将注释插入表格单元格崩溃 Word
【发布时间】:2015-06-17 07:53:28
【问题描述】:

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

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);                                           
  }

插入评论时Word崩溃

【问题讨论】:

  • Word 崩溃?没有错误信息? Word 是否安装正确?哪个版本的Word?请添加您的问题的答案!
  • Microsoft Word 2013,Word 安装正确,没有错误信息,也不例外,只是崩溃“Microsoft Word 已停止工作”然后重新启动 microsoft word。如果我在平面文本中插入评论,效果很好
  • 互操作版本 14.0.0.0

标签: c# .net ms-word interopservices


【解决方案1】:

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

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-08
    • 2017-02-12
    • 2010-10-08
    • 2019-05-29
    相关资源
    最近更新 更多