Free Support Forum - aspose.com

Embed excel graph in powerpoint slide using com.aspose.slides library

given an excel workbook which could contain multiple sheets and multiple charts,
how can I navigate through the workbook to select a specific graph,
and then embed that graph and it's supporting data in a power point slide?

what I need is for a user to see the graph when opening the presentation,
but then be able to edit the supporting data as is available through
regular powerpoint functionality...

Hi Peter,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your interest in Aspose.Slides.

Well you need to use Aspose.Cells for this purpose. Using Aspose.Cells, you can access the Excel file and particular workbook inside that. Then you can export that workbook as OLE object to any particular slide. Please follow the thread posts at link1 and link2 for further clarifications.

Thanks and Regards,

hello Mudassir…
thank you for the response…

yes…I can navigate through a workbook using
the com.aspose.cells library, but still need to figure
out 2 things:

  1. once I find the desired chart, which could be one
    of many in a workbook or even in a worksheet, how can that specific
    chart be identified as the chart which appears on the slide?
    must I extract it to a new workbook?

  2. using the code at the following two links:
    http://www.aspose.com/community/forums/post/175256/creating-excel-chart-and-embedding-them-as-ole-object-inside-a-presentation.aspx

http://www.aspose.com/community/forums/post/210780/convert-chart-to-image-for-java.aspx

I’ve managed to successfully embed a chart in a slide
and create a picture for the chart…the problem is the
picture colors don’t match the chart colors…and as soon
as the chart is activated in the slide, the powerpoint application
screen bounces around a bit and the picture pretty
much disappears forever…is there a way to just display
the chart without the extra picture? or at least make them
an exact match?

Thank you!

Hi,
For the first part of your question about showing specific chart in a slide, after investigation I think it is required to copy the desired chart to a new workbook or worksheet. Following is the Code sample for your reference:
Workbook wb = new Workbook();
wb.open("template.xls");
Worksheets wss = wb.getWorksheets();
Worksheet srcSheet = wss.getSheet(0);
Chart chartSrc = srcSheet.getCharts().getChart(0); //assume it is the desired chart to be shown in slides
Worksheet chartSheet = wss.addSheet(SheetType.CHART);
wss.setActiveSheet(chartSheet); //make this chart sheet active so when embed it into slides the chart will be shown
chartSheet.getShapes().addCopy(chartSrc.getChartShape());
...//save the workbook and embed it into slides


Thank you.

Hello Peter,

For the second part of your question please elaborate the issue further and share the problematic presentation data with us for further verifications.

We are sorry for your inconvenience,

hello Mudassir...

I'm building a chart using the cells library
and embedding it in a powerpoint presentation using the slides library...

as part of embedding the chart on the slide the following code
is used to create the foreground picture for the chart:

com.aspose.cells.Chart chart = wb.getWorksheets().getSheet("ChartSheet").getCharts().getChart(0);
ImageOptions imgOpts = new ImageOptions();
imgOpts.setImageFormat(ImageFormat.PNG);
imgOpts.setFashion(FileFormatType.EXCEL2003);
chart.toImage(fileName + ".png", imgOpts);

when opening the completed powerpoint presentation the chart appears
and has the correct data, but the colors are incorrect...

activating the chart with either a right-click or a double-click will
successfully open it for editing, and it also refreshes the chart such
that the colors display correctly...

so...the question is -- how can I make the chart colors appear correctly
without forcing the user to activate the chart?

Thank you!


Hi,

Please try the attached version of Aspose.Cells for Java. If you still find the image’s color issue, kindly post your generated excel file (containing the chart) or sample code to create the chart and its output image here, we will check your issue soon.

Thank you.

hello Amjad,
the updated version of the cells library
seems to fix the problem!

I will test further and reply here if there are further issues...

Thank you!

Hi Amjad,

We are using Aspose Slides for Dot Net.
As part of embedding excel chart on the powerpoint slide, with the following code,

Bitmap imgChart = new Bitmap(wb.Worksheets[0].Charts[0].ToImage());

var pic = new Aspose.Slides.Picture(presentation, imgChart);
int picId = presentation.Pictures.Add(pic);
oleFrame.PictureId = picId;

produces the chart image of poor quality. But activating the chart with either a right-click or a double-click fixes the blurry effect.
To be noted, No “ImageOrPrintOptions” attributes improves the quality. (file attached)

So, my question is, how I can achieve the proper look and feel of the chart without forcing the user to activate the chart.

Thank you!

Zerin.


Hi Zerin,

Well, I think you may try to convert the chart into vector graphics e.g emf to paste it into the slide if it can imrprove the quality of the image.

Also, we will soon look into it.

Thank you.

Hi Amjad,

I am not benefited after using the image format Emf.
Could you please provide an example on how you meant to do it?

Thanks,
Zerin.

Hello,

As I couldn’t update the image in a programmatic way, so I used Macro on Open event of the presentation. I took help from Technical Articles for Aspose Updating OLE objects automatically using MS
PowerPoint Add-In

But I had to modify the code like this to make it work:

Sub Auto_open()
Dim oShape As Shape
Dim oSlide As Slide

For Each oSlide In ActivePresentation.Slides
For Each oShape In oSlide.Shapes

If oShape.Type = msoEmbeddedOLEObject Then

Set oChart = oShape.OLEFormat.Object.charts(1)
With oChart
.ChartArea.AutoScaleFont = False
End With
Set oChart = Nothing
End If
Next oShape
Next oSlide
End Sub


Thanks,
Zerin.