gitbrent / PptxGenJS

Create PowerPoint presentations with a powerful, concise JavaScript API.
https://gitbrent.github.io/PptxGenJS/
MIT License
2.62k stars 611 forks source link

Fix multi lvl categories in embedded .xlsx #1330

Open MariusOpeepl opened 2 months ago

MariusOpeepl commented 2 months ago

Change Summary

A key/value object was added for shared strings so that it can be used to fetch the sharedString index of category axes and removed an unneeded summand when calculating a label's column.

Change Description

Calculating the col and row position of the category labels

getExcelColName(idx + 1 + idy) did not need idx, and caused each subsequent row of labels to be shifted one more column to the right from the previous row.

Calculating the category label indexes in sharedStrings.xml

I could not find a fix for the calculation, so I instead create a key/value object (e.g. { 'Category Label': 4 }) that maps strings to their respective indexes in sharedStrings.xml, and use it to get the correct index of any given string.

Other

There is at least one WIP: FIXME: note around this code; I did not remove it, as I wasn't sure if the note was referencing this issue in particular.

Lastly, I only updated the accessing of shared strings for IS_MULTI_CAT_AXES, as I'm not too familiar with the other chart types and I'd risk introducing more bugs. The dictionary object should get correctly populated by all chart types, though.

Change Type

Motivation and Context

While the PPTX charts with multiple category axes looked fine, their embedded Excel contained malformed data, and upon opening the Excel, the related chart would also break.

Checklist before requesting a review

Screenshots / Sample Code (if appropriate)

Before After
Microsoft_Excel_Worksheet64_broken Microsoft_Excel_Worksheet64