How to change PowerPoint chart data using .NET?
I have a PowerPoint template that has one slide and this slide has a diagram. I would like to be able to manipulate the chart data using .NET.
So far I have some code that ...
- unpacks the Powerpoint file.
- unpacks the embedded excel file (ppt \ embeddings \ Microsoft_Office_Excel_Worksheet1.xlsx)
- It successfully manipulates the data in the excel sheet and zips it back.
- Opens and processes ppt \ charts \ chart1.xml
- The powerpoint is then zipped and delivered to the user
This results in a PowerPoint file that shows a blank graph. But when I click on the chart and go to edit data, it refreshes the data and shows the correct graph.
I believe my problem is related to the chart1.xml I am generating. I compared my generated version with the PowerPoint generated version and they are almost identical. The only differences are in the meanings for <c:crossAx/>
and <c:axId/>
.
There are also some rounded differences in the data. But I don't feel like this will result in an empty diagram.
Is there another file that I need to change? Does anyone have any ideas as to what else I should try to get this to work?
a source to share
This is probably a combination of axID value and rounding questions. The axis id is probably asking for an integer value and you can supply one / two. So the cached data in chart1.xml doesn't know how to display.
Try the same manipulations that you did, but instead of opening the result in PowerPoint, change the .pptx extension to .zip, unzip, and then manually correct the rounding problems to match the original rounding. Then pin the backup, change the extension to .pptx, and open it in PowerPoint. If that fixes the display issue, you can confirm that it is a rounding issue.
Alternatively, and along the same lines. Open the resulting PPTX in PowerPoint as you did, and after you right-click and register the graph, save as a different filename and compare it to the automatic result.
a source to share