singerla / pptx-automizer

A template based pptx generator for Node.js
MIT License
63 stars 11 forks source link

Modifying table with first cell empty #112

Closed llermaly closed 2 months ago

llermaly commented 2 months ago

I'm trying to modify this slide's table:

image

And having this error:

TypeError: Cannot read properties of undefined (reading 'parentNode') at Function.insertAfter (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/xml-helper.ts:511:26) at XmlElements.text (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/xml-elements.ts:30:15) at ModifyXmlHelper.createElement (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/modify-xml-helper.ts:111:33) at ModifyXmlHelper.assertElement (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/modify-xml-helper.ts:85:14) at ModifyXmlHelper.modify (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/modify-xml-helper.ts:38:28) at ModifyXmlHelper.modify (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/modify-xml-helper.ts:59:16) at ModifyXmlHelper.modify (/Users/gustavo/Documents/projects/labs/pptx-automizer/src/helper/modify-xml-helper.ts:59:16) at /Users/gustavo/Documents/projects/labs/pptx-automizer/src/modify/modify-table.ts:36:20 at Array.forEach () at /Users/gustavo/Documents/projects/labs/pptx-automizer/src/modify/modify-table.ts:34:18

If I fill the first cell it works, but unfortunately I can't ask the users to modify their pptx.

Is this a bug or expected behavior and what's the way to fix it? I found this issue: https://github.com/singerla/pptx-automizer/issues/76 , but this case seems different because the table is not technically empty, and I don't want to put anything in that position anyways. Could the cell be ignored instead of raising an error maybe?

Thanks!

singerla commented 2 months ago

That's a bug. The latest commit contains a quick fix to skip a cell without content. Please let me know, if this helps you out.

There is a difference between an empty cell in a recently created table and an empty cell after manually remove all characters. The latter will still contain a '' parent node, which is necessary for XmlElements.text to work. I still need to handle this.

Thanks a lot for pointing out!