【问题标题】:Define range to text inside table cell将范围定义为表格单元格内的文本
【发布时间】:2016-03-19 23:38:08
【问题描述】:

我使用 Word Interop 在表格的单元格中插入一些文本。添加文本后,我想在该文本中插入一个书签。目前我可以选择整个单元格并向其插入书签,但我希望书签只属于文本。

var cell = tb.Cell(row, col);
cell.Range.Text = "MyText";
Microsoft.Office.Interop.Word.Range rng = tb.Cell(row, col).Range;
rng.Select(); // this line is useful to see the range where bookmark will be placed
rng.Bookmarks.Add("BookmarkName", rng);

【问题讨论】:

    标签: c# ms-word cell office-interop


    【解决方案1】:

    单元格内的范围仍然包括单元格结束标记。您需要在添加书签之前通过移动末端来相应地调整范围:

    rng.MoveEnd Microsoft.Office.Interop.Word.WdUnits.wdCharacter, -1
    rng.Select(); // this line is useful to see the range where bookmark will be placed
    rng.Bookmarks.Add("BookmarkName", rng);
    

    【讨论】:

      猜你喜欢
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多