docx
                                
                                
                                
                                    docx copied to clipboard
                            
                            
                            
                        Error opening docx including Table in microsoft word
Docx including a Table element gives the following error when opening in latest version Microsoft Word. The same file works fine in LibreOffice, as well as online on Google Docs. I narrowed it down to the Table just by adding and removing elements. Behavior is similar to several closed issues, however these previous issues have either all been closed with fixes applied, or do not apply to this simple example.
I can resave the file in LibreOffice and it opens fine after that in Microsoft Word. I've attempted to dig into the xml a bit but don't have the experience with that sort of stuff to make much sense of it.
I've included a zip file with the original unaltered docx that does not open in Word as well as the resaved one that does - maybe that'll help someone with troubleshooting? example files.zip
Tested using the example below ( this is directly from the basic example in the docs - https://raw.githubusercontent.com/dolanmiu/docx/master/demo/4-basic-table.ts)
const doc = new docx.Document({
  sections: [{
    children: [
      new docx.Paragraph({
        children: [
          new docx.Table({
            columnWidths: [3505, 5505],
            rows: [
              new docx.TableRow({
                children: [
                  new docx.TableCell({
                    width: {
                      size: 3505,
                      type: docx.WidthType.DXA,
                    },
                    children: [new docx.Paragraph("Hello")],
                  }),
                  new docx.TableCell({
                    width: {
                      size: 5505,
                      type: docx.WidthType.DXA,
                    },
                    children: [],
                  }),
                ],
              }),
              new docx.TableRow({
                children: [
                  new docx.TableCell({
                    width: {
                      size: 3505,
                      type: docx.WidthType.DXA,
                    },
                    children: [],
                  }),
                  new docx.TableCell({
                    width: {
                      size: 5505,
                      type: docx.WidthType.DXA,
                    },
                    children: [new docx.Paragraph("World")],
                  }),
                ],
              }),
            ]
          })
        ],
      }),
    ],
  }]
});
Please let me know if any more info is needed to look into this!
@nicwilliams1 I ran into this exact issue as well. I worked around it by not putting tables inside paragraphs. Here's the snippet that worked for me.
const doc = new docx.Document({
      sections: [
        {
          children: [
            ...paragraphs,
            mainTable,
            new docx.Paragraph({
              spacing: {
                after: 200,
                before: 200,
              },
              children: [
                new docx.TextRun(`Table 4-24: ${this.selectedAlgorithm.name} Flyout Chart`),
              ]
            }),
            flyoutChartTable,
          ]
        },
      ],
    });
                                    
                                    
                                    
                                
Yeah you cant put Tables inside Paragraphs. They both have to be top level children.
Types need fixing to protect against this