书签功能

获取书签内容

  1. /*
  2. * @param: string
  3. * @return: string
  4. */
  5. let bookmarkText = await demo.WordApplication().ActiveDocument.GetBookmarkText(name)

替换书签

  1. /*
  2. * @param: {Data: [{name: string, type:'url'|'text', value: string}]} 参数[{书签名,替换成类型, 替换的value}]
  3. * @return: bool
  4. */
  5. let isReplaceSuccess = await demo.WordApplication().ActiveDocument.ReplaceBookmark([{name: '123', type: 'text', value: '234'} ])

获取所有书签

  1. /*
  2. * @return: [{begin: string, end: string, name: string}]
  3. */
  4. let bookmarks = await demo.WordApplication().ActiveDocument.Bookmarks.Json()

添加书签

  1. /*
  2. * @param: { Name: string, Range: { Start: number, End: number } } 必需
  3. * @return: string
  4. */
  5. await demo.WordApplication().ActiveDocument.Bookmarks.Add({Name, Range})

删除书签

  1. /*
  2. * @param: { Index: string } 代表单个对象的名称的字符串, 序号位置暂不支持 必需
  3. * @return: string
  4. */
  5. await demo.WordApplication().ActiveDocument.Bookmarks.Item({Index}).Delete()

跳转到指定的书签

  1. /*
  2. * @param: { What?: WdGoToItem, Which?: WdGoToDirection.wdGoToAbsolute, Count?: number, Name?: string}
  3. * Enum: {
  4. * WdGoToItem: {
  5. * wdGoToBookmark: -1,
  6. * }
  7. * WdGoToDirection: {
  8. * wdGoToAbsolute: 1
  9. * }
  10. * }
  11. */
  12. await app.ActiveDocument.Selection.GoTo(Enum.WdGoToItem.wdGoToBookmark, Enum.WdGoToDirection.wdGoToAbsolute, undefined, 'bookmarkName')
  13. // 或者
  14. await app.ActiveDocument.Selection.GoTo({
  15. What: Enum.WdGoToItem.wdGoToBookmark,
  16. Which: Enum.WdGoToDirection.wdGoToAbsolute,
  17. Name: 'bookmarkName' // 书签名
  18. })