singerla / pptx-automizer

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

Updating Chart Title and formatCode #96

Closed jrking4 closed 8 months ago

jrking4 commented 8 months ago

I love this library! It is super helpful to maintain branding on PPT generation.

I am looking to modify the chart title and formatCode. ideally is there an easy way to make minor edits to the chart XML file? i could simply traverse the file and make the changes i need, I didnt see a way to easily do this?

singerla commented 8 months ago

Hi! I'm always happy to hear :)

Please take a look at src/helper/modify-chart-helper.ts for a basic example. It should be suitable for chart title with some modifications.

Regarding formatCode, it's more complicated. There is already a modifier for chart axis, take a look at setAxisRange in src/helper/modify-chart-helper.ts. If you need this for data labels, a lot more modification is required and you need matching formats for your xlsx worksheet data source, too. Usually, I prefer number formats as origin to avoid any trouble.

I'm not sure on this, but you probably need to apply your modifications to formatCode to more than a single xml.

You can modify slide element, chart and workbook in one go:

static yourCustomChartModifier =
  (element: XmlElement, chart: XmlDocument, workbook: Workbook): void => {
      // XmlHelper.dump(chart)
      // XmlHelper.dump(workbook.table)
    };
singerla commented 8 months ago

See it in action: https://github.com/singerla/pptx-automizer/blob/main/__tests__/modify-chart-plot-area.test.ts

jrking4 commented 8 months ago

thanks! adding the chart title was super easy. just added a pull request #97 . i agree formatCode may be a little too complex. i am ideally looking to convert a 0.4 to 40% on a chart. i guess instead i could have a separate template slide for percent

singerla commented 8 months ago

Thanks a lot for sharing your solution!