gitbrent / PptxGenJS

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

dataLabelFormatCode option creates corrupted file if the value includes quotes #834

Closed kornarakis closed 3 years ago

kornarakis commented 4 years ago

Category

Bug

Version

Please specify what version of the library you are using: [ 3.3.1 ]

Please specify what version(s) of PowerPoint you are targeting: [ 365 ]

Expected / Desired Behavior / Question

On Bar chart type when using the dataLabelFormatCode with a value like #,##0.0"%" the generated pptx file is corrupted.

Observed Behavior

My demo numbers are

value
A 15.5
B 20.32

The expected behavior is to show the numbers on the bar charts as 15.5% and 20.3%. The format code #,##0.0"%" is working fine if you set it in Powerpoint directly.

Steps to Reproduce

Create a bar chart with the following code

 let testdata = [{
    name: '',
    labels: ['A', 'B'],
    values: [15.5,20.32 ],
  }]
 slide.addChart(pptx.ChartType.bar, testdata, {
        catAxisLabelFontSize: 15,
        catAxisLabelColor: '75D4D6',
        catAxisLabelFontBold: true,
        catAxisLineShow: false,
        valAxisLineShow: false,
        valAxisHidden: true,
        lineSize: 4,
        barGapWidthPct: 50,
        dataLabelPosition: 'ctr',
        dataLabelFontSize: 10,
        dataLabelColor: '000000',
        dataLabelFormatCode: '#,##0.0"%"',
        showValue: true,
        showTitle : false,
        valGridLine: { style: 'none' },
        catGridLine: { style: 'none' },
        x: 1.81,
        y: 2.51,
        w: 1.94,
        h: 1.73,
      })
galzo commented 3 years ago

According to official Microsoft documentation, you can add symbols and characters by wrapping them with "". another option is to use an escaping character. so in your case you should use: \% escaping seems to be working on PptxGenJS, but ""seems to corrupt the file.

I'll try to fix this issue.

galzo commented 3 years ago

Issue Fixed. I'll send a PR now.

gitbrent commented 3 years ago

Thanks for reporting this @kornarakis

Fixed thanks to @galzo