public void UpdateBookMarkText(string bookmarkName, string text)
{
try
{
object bkName = bookmarkName;
Bookmark bk = document.Application.ActiveDocument.Bookmarks.get_Item(ref bkName);
var newend = bk.Range.Start + text.Length;
var name = bk.Name;
Range range = bk.Range;
bk.Range.Text = text;
range.End = newend;
document.Application.ActiveDocument.Bookmarks.Add(name, range);
MessageBox.Show("操作成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这段代码实现了一个更新文档中书签文本的功能,通过指定书签名称和新文本,更新书签内容并确保书签名与更新后的范围对应。
628

被折叠的 条评论
为什么被折叠?



