How do I access the datagrid for a graph/chart that already exists in a PPT template?
I have a file with a chart that needs to be updated.I know that I need
Aspose.Excel and Aspose.Powerpoint, which I have. But there seems to be
no documentation on doing this.
A code example would be great.
Can anyone help me with this…?
At first, you can read data only from Excel Charts but not from standard charts.
With Aspose.PowerPoint you can get byte array. Please check OleObjectFrame.ObjectData property.
After that you can use this array to create MemoryStream:
MemoryStream ms = new MemoryStream(bytes);
And use it as source for Aspose.Excel.
I’m affraid I can’t show examples how to read real chart’s data with Aspose.Excel.
It’s better to ask in Aspose.Excel forum.
I’m afraid that doesn’t really answer my question though…
I have a Powerpoint template which contains several pre-defined charts.
Through a web interface, the user will select a specific chart type,
define some data parameters (Year, Country etc) and then click submit.
I then need to get the dataset, open the Powerpoint file, find the
relevant chart, update the chart’s datagrid with my own dataset, and
then send the updated Powerpoint file to the user.
I was led to believe that this is possible in a previous thread in this forum:
Please can you provide me with a code sample of how the Powerpoint chart update can be done.
Please check code:
// Open presentation and get OLE data
Presentation pres = new Presentation(“ppt1.ppt”);
OleObjectFrame shape = (OleObjectFrame) pres.Slides.Shapes;
byte xlsData = shape.ObjectData;
// Open chart with Aspose.Excel
MemoryStream stream1 = new MemoryStream(xlsData);
Excel excel = new Excel();
// Change data grid
// Save excel chart back to the memory stream
MemoryStream stream2 = new MemoryStream();
// Replace chart data in our presentation and save ppt
shape.ObjectData = stream2.ToArray();
I’ve tried using your code and unfortunately I’m getting an error…
My code as follows:
'open file and get OLE data
Dim pres As New Presentation(“c:\temp\graph\pp.ppt”)
Dim shape As OleObjectFrame = pres.Slides(0).Shapes(0)
Dim xlsData As Byte() = shape.ObjectData
'open chart with aspose.excel
Dim stream1 As New MemoryStream(xlsData)
Dim excel As New Excel
excel.Open(stream1, FileFormatType.Default) <-- error thrown here –
'save excel chart back to memory stream
Dim stream2 As New MemoryStream
'replace chart data in presentation and save
shape.ObjectData = stream2.ToArray
Screenshot of error is attached.
Please could someone help me on this…?
I didn’t get notification about your previous post.
Are you sure your presentation has Excel Chart?
As I wrote before you can open Excel Charts but can’t open charts which are created directly in PowerPoint.
Sorry, but I don’t understand. The code example you posted does not work!
You’re defining xlsData as a byte array which contains the Powerpoint
chart’s data. You’re then creating a stream using this byte array, and
then using the stream to open a new instance of Aspose.Excel so that
the chart data can be updated using Aspose.Excel.
The chart I’m trying to update was created directly in Powerpoint, but
you never said before that this would be a problem. I can see that both
the byte array and stream are created and contain information before
you try to open Excel, so I don’t understand why it doesn’t work.
Please can you help me sort this out - it’s becoming quite urgent for me now!!
Please check third message in this thread. Also you can find similar questions in this forum.
OLE Object (byte array in our case) in the PowerPoint is gzipped file so it’s necessary to
use specail program for each type of OLE Object.
Standard PowerPoint charts created with MS Graph, Excel Charts - with MS Excel.
Aspose.Excel can read Excel Charts but can’t read MS Graph charts. It’s very simple.
Teoretically if you absolutely must read standard MS Graph charts you can save this byte array to a file
and try to edit it with MS Graph through OLE automation.
I’m sorry, but I am finding your answers confusing because you don’t seem to be addressing my problem.
Please see the 4th post in this thread, where I ask for a code sample.
You then gave me a code sample which does not work.
I need to be able to open Powerpoint and update an existing chart with
new data. I need to do it this way because the Powerpoint file is a
company template containing logos, colors etc which I do not want to
have to re-create each time. The charts I need to update also contain
specific colors and titles etc which fit the company’s template.
I have just purchased an Enterprise subscription as I was led to believe this was possible, but you’re now telling me it is not.
Please could you give me link to my post where I wrote it’s possible to change standard charts in a presentation?
I always write about excel charts.
Code sample I gave you works for presentations with embedded excel charts without any problems.
How your presentations are created? Is it possible to use excel charts instead of standard?
I understand now. It was not clear that the chart had to be an Excel embedded object.
This brings me to another issue though. Unfortunately this will not
satisfy my client as the embedded charts are difficult to edit and
modify (colors, titles etc) and also cannot be resized easily.
Is there any way that existing charts in Powerpoint - that were created
in Powerpoint - can be updated using Aspose? i.e. the charts are
Powerpoint charts, NOT embedded objects from Excel.
This is crucial to my project, so please let me know.
Thanks - and sorry for the confusion
Sorry, there are no ways to update standard PoweProint charts with only Aspose components.
Is this something that will be developed in future?
It would be a fantastic feature to have!!
MS Graph uses old Excel format and If I’m not mistaken Microsoft had planes to present new
applicaction for creating charts based on some new file format.
So I’m not sure if it’s a good idea to implement old formats.