Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waterfall chart throws Zipped file not found: ppt/charts/chartNaN.xml #28

Closed
AlexanderKulia opened this issue Oct 28, 2022 · 11 comments · Fixed by #36
Closed

Waterfall chart throws Zipped file not found: ppt/charts/chartNaN.xml #28

AlexanderKulia opened this issue Oct 28, 2022 · 11 comments · Fixed by #36
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@AlexanderKulia
Copy link

Hi, very cool library! Unfortunately, I encountered an issue that prevents me from using waterfall charts.

Stack trace

(node:4420) UnhandledPromiseRejectionWarning: Error: Zipped file not found: ppt/charts/chartNaN.xml
    at Function.<anonymous> (/node_modules/pptx-automizer/src/helper/file-helper.ts:56:13)
    at Generator.next (<anonymous>)
    at /node_modules/pptx-automizer/dist/helper/file-helper.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/node_modules/pptx-automizer/dist/helper/file-helper.js:4:12)
    at Function.zipCopy (/node_modules/pptx-automizer/dist/helper/file-helper.js:52:16)
    at Chart.<anonymous> (/node_modules/pptx-automizer/dist/shapes/chart.js:149:44)
    at Generator.next (<anonymous>)
    at /node_modules/pptx-automizer/dist/shapes/chart.js:8:71
    at new Promise (<anonymous>)

Steps to reproduce:

  1. create a new presentation called "root.xlsx" with one slide
  2. create a new presentation called "waterfall.xlsx", add a waterfall chart to it and call it "WATERFALL"
  3. try adding the slide from "waterfall" to "root"
  4. Error: Zipped file not found: ppt/charts/chartNaN.xml

Minimal code

const ppt = Automizer.loadRoot('root.pptx').load('waterfall.pptx', 'waterfall');

ppt.addSlide('waterfall', 1, (slide) => {
    slide.modifyElement('WATERFALL', [
        modify.setChartData({
            series: [{ label: 'Value' }],
            categories: [
                { label: 'Revenue', values: [500] },
                { label: 'Cost', values: [-100] },
                { label: 'Profit', values: [400] },
            ],
        }),
    ]);
}

const summary = await ppt.write('test.pptx');
console.log(summary);

System

macOS Monterey v12.6
PowerPoint for Mac v16.66 (22100900)

@singerla
Copy link
Owner

Hi! I'm glad you like pptx-automizer! :)
I did not test the library against waterfall charts, i need to dig deeper into this. My first impression: automizer usually manipulates ppt/charts/chart1.xml, but waterfall uses ppt/charts/chartEx1.xml. I did not expect to have different filenames, but take a look at modifyChartData() in src/shapes/chart.ts. I guess it needs to fork the filename depending on the type of chart.

@singerla singerla added the bug Something isn't working label Oct 28, 2022
@singerla singerla self-assigned this Oct 28, 2022
@singerla
Copy link
Owner

singerla commented Nov 3, 2022

I'm still working on this in a seperate branch, but it requires some refactoring. This problem also affects e.g. map charts, needs to be solved.

@AlexanderKulia
Copy link
Author

Hi, any update on this issue?

@singerla
Copy link
Owner

singerla commented Dec 5, 2022

Hi, I'm very busy at the moment, but I'll try to solve this by the end of the week.

@singerla
Copy link
Owner

singerla commented Dec 7, 2022

Hi @AlexanderKulia, I could make some steps towards chartEx implementation, but it's not finished yet. You can run dev.ts: The first series and all categories are added properly, but ppt will give you a "repair"-message. It might be related to cx:subtotals in \ppt\charts\chartEx1.xml, but I'm not sure on this.

@singerla singerla added the enhancement New feature or request label Dec 7, 2022
@singerla singerla linked a pull request Dec 7, 2022 that will close this issue
@singerla
Copy link
Owner

singerla commented Dec 8, 2022

This should work now! Please test it with your custom waterfall chart.

Use a modifier like this:

slide.addElement('ChartWaterfall', 1, 'Waterfall 1', [
    modify.setExtendedChartData(<ChartData>{
          series: [{ label: 'series 1' }],
          categories: [
            { label: 'cat 2-1', values: [100] },
            { label: 'cat 2-2', values: [20] },
            { label: 'cat 2-3', values: [50] },
            { label: 'cat 2-4', values: [-40] },
            { label: 'cat 2-5', values: [130] },
            { label: 'cat 2-6', values: [-60] },
            { label: 'cat 2-7', values: [70] },
            { label: 'cat 2-8', values: [140] },
        ],
    }),
]);

Please notice:

  • You need to use setExtendedChartData instead of setChartData
  • At the moment, it is required to place (at least) a blank space into cell A1 of your template's datasheet to avoid a problem with editing data.
  • There is currently no modifier available for cx:subtotals. Please give me a hint how to implement this properly.

I have only tested ppt's default waterfall chart. Please let me know if this works for your stuff, too 😃

PS: Please excuse the confusing merges an PRs, I'm still practising on how to keep branches in sync. 😅

@AlexanderKulia
Copy link
Author

hey, thank you for the update. will check the changes on the weekend and let you know

@AlexanderKulia
Copy link
Author

hi @singerla I was able to add a waterfall chart and it looks good to me. however I noticed that I cannot view Excel data by right clicking on the newly added waterfall chart. Excel just opens its default page, not the data sheet

Can you reproduce the issue at you end?

import Automizer, { ChartData, modify } from './index';

const automizer = new Automizer({
  templateDir: '.',
  outputDir: '.',
});

const main = async () => {
  const ppt = automizer.loadRoot('root.pptx').load('charts.pptx', 'charts');

  ppt.addSlide('charts', 1, (slide) => {
    slide.addElement('charts', 1, 'WATERFALL', [
      modify.setExtendedChartData(<ChartData>{
        series: [{ label: 'VALUE' }],
        categories: [
          { label: 'CAT1', values: [856] },
          { label: 'CAT2', values: [-760] },
          { label: 'CAT3', values: [96] },
        ],
      }),
    ]);
  });

  const res = await ppt.write('out.pptx');
  console.log(res);
};

main();

@singerla
Copy link
Owner

I'm sorry, can't reproduce with __tests__/pptx-templates/ChartWaterfall.pptx. Must be something inside your customized template. Did you notice:

  • At the moment, it is required to place (at least) a blank space into cell A1 of your template's datasheet to avoid a problem with editing data.

Excel tells you more about errors inside a file: You can unzip your output-pptx an go to embeddings-directory. Open the the files with a -created-flag and take a look at the message excel throws.

@AlexanderKulia
Copy link
Author

My bad, I thought A1 wasn't empty but it was. Editing works now 👍

@singerla
Copy link
Owner

Allright, I'm glad to hear :)
We need to handle empty cells properly, please take a look at #39.

Thanks a lot again for mentioning this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants