仅获取选定表格单元格内的段落项目

问题描述

我正在使用 Office JS 开发 Word 插件。我在获取表格选择中当前选定的段落项目时遇到问题,并选择了表格单元格的子集。 API 只返回最后选择的表格行的段落项。

我只想获取当前选定单元格中的特定段落:

enter image description here

问题是总是只接收选择的最后一行:

enter image description here

代码很简单,但我不知道我做错了什么:

export async function getSelection() {
   await window.Word.run(async (context) => {
      const range = context.document.getSelection()
      const paragraphs = range.paragraphs
    
      range.load(['paragraphs'])
      paragraphs.load()
    
      await context.sync()
    
      console.log('Paragraphs',paragraphs.items)
   })
}

我正在尝试使用 TableCellCollection,但我不知道如何获取它们。有人可以帮助我吗? 链接到有关 TableCellCollection 的文档: https://docs.microsoft.com/en-us/javascript/api/word/word.tablecellcollection?view=word-js-preview

解决方法

对于瑞克: 如果您选择整行(包括最后一行字符),则 getSelection 返回所有选定的单元格: enter image description here enter image description here

如果您执行相同操作但仅选择单元格,则错误再次出现: enter image description here enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...