singerla / pptx-automizer

A template based pptx generator for Node.js
MIT License
68 stars 12 forks source link

Modifying table text with merged cells #132

Open alucardmmc opened 3 days ago

alucardmmc commented 3 days ago

Hi! I'm trying to delete all text from the cells of a table. The table in this case has horizontal and vertical merged cells. This works correctly with a PPTX created from Powerpoint. But when trying the same with a PPTX created from Google Slides, I get the following error:

TypeError: Cannot read properties of undefined (reading 'getAttribute')
    at XmlElements.textRangeProps (/app/node_modules/pptx-automizer/src/helper/xml-elements.ts:63:41)
    at XmlElements.text (/app/node_modules/pptx-automizer/src/helper/xml-elements.ts:31:24)
    at ModifyXmlHelper.createElement (/app/node_modules/pptx-automizer/src/helper/modify-xml-helper.ts:111:33)
    at ModifyXmlHelper.assertElement (/app/node_modules/pptx-automizer/src/helper/modify-xml-helper.ts:85:14)
    at ModifyXmlHelper.modify (/app/node_modules/pptx-automizer/src/helper/modify-xml-helper.ts:38:28)
    at ModifyXmlHelper.modify (/app/node_modules/pptx-automizer/src/helper/modify-xml-helper.ts:59:16)
    at ModifyXmlHelper.modify (/app/node_modules/pptx-automizer/src/helper/modify-xml-helper.ts:59:16)
    at /app/node_modules/pptx-automizer/src/modify/modify-table.ts:36:20
    at Array.forEach (<anonymous>)
    at /app/node_modules/pptx-automizer/src/modify/modify-table.ts:34:18

This is the PPTX that I've been using for testing: GS_Tables_Merged.pptx

I think this issue happens for Google Slides because, the <a:tc> when it's merged, it doesn't have any <a:txBody> when compared to a PPTX from Powerpoint.

image

Is there maybe a way to, when modifying text, skip some cells from being changed? Currently I modify the text doing something like this:

const data: TableData = {
    body: [
        { values: ['', '', ''] },
        { values: ['', '', ''] },
        { values: ['', '', ''] },
        { values: ['', '', ''] },
        { values: ['', '', ''] },
        { values: ['', '', ''] },
    ],
};

slide.modifyElement('table', [
    modify.setTable(data1, {
        adjustHeight: false,
        adjustWidth: false,
    }),
]);

Thanks!