问题是Range
您的代码片段中指定的目标是整个单元格。您需要“折叠”Range
才能在单元格内。(将范围想象为选择。如果单击单元格的边缘,则会选择整个单元格,包括其结构元素。如果然后按左箭头,则选择会折叠成闪烁的工字梁。)
要转到单元格的开头:
Word.Range rngCell = row.Cells[2].Range;
rngCell.Collapse(Word.WdCollapseDirection.wdCollapseStart);
rngCell.InsertCrossReference(WdReferenceType.wdRefTypeEndnote, WdReferenceKind.wdEndnoteNumberFormatted, 1);
如果单元格有内容并且您希望它位于内容的末尾,那么您可以使用它wdCollapseEnd
。棘手的部分是这会将目标点放在下一个单元格的开头,因此必须将其移回一个字符:
Word.Range rngCell = row.Cells[2].Range;
rngCell.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
rng.MoveEnd(Word.WdUnits.wdCharacter, -1);
rngCell.InsertCrossReference(WdReferenceType.wdRefTypeEndnote, WdReferenceKind.wdEndnoteNumberFormatted, 1);