Get paragraph items within only the selected table cells

368 Views Asked by At

I am working on an add-in for Word using Office JS. I have an issue getting the current selected paragraphs items within a Table selection, with a subset of table cells selected. The API only returns the paragraph items of the last selected Table Row.

I would like to get only the specific paragraphs within the currently selected cells:

enter image description here

The problem is that always only receive the last row of the selection: enter image description here

The code is so simple but I have not idea about what I am doing wrong:

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)
   })
}

I am trying to use TableCellCollection but I have not idea about how get them. Could anyone help me? Link to the documentation about TableCellCollection: https://learn.microsoft.com/en-us/javascript/api/word/word.tablecellcollection?view=word-js-preview

1

There are 1 best solutions below

0
On

For Rick: If you select entire rows (including the final row character) then getSelection returns all selected cells: enter image description here enter image description here

If you do the same but it selecting only the cells then the bug appears again: enter image description here enter image description here