Free Support Forum - aspose.com

Export Excel charts and Ranges from the worksheets into PowerPoint Slides

Hi Expert,

I want to make a presentation by using many charts and range of many worksheets from a workbook.

I done it using following code

Aspose.Cells.Charts.Chart chart = workbook.Worksheets[“Sheet1”].Charts[“chrtScores”];
filePath = strPath + “PieChart.out.emf”;
// Convert the chart to an image file.
chart.ToImage( filePath, System.Drawing.Imaging.ImageFormat.Emf);
image = new Bitmap(filePath);

//Create an IPPImage object using the bitmap object
imgx = pres.Images.AddImage(image);

// ShapeType ShapeTypeEx = new ShapeType();
// sld = pres.Slides.AddEmptySlide();
sld.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 50, imgx.Width, imgx.Height, imgx);

but image quality is very poor.

Please suggest me how i can export a good quality of images from excel to PowerPoint.

I also used below method

Bitmap imgChart = workbook.Worksheets[“Case 1”].Charts[“chrtMVAWaterFall”].ToImage();
//Save the workbook to stream
MemoryStream wbStream = workbook.SaveToStream();
AddExcelChartInPresentation(pres, sld, wbStream, imgChart);
//-------------------------------------
static void AddExcelChartInPresentation(Presentation pres, ISlide sld, Stream wbStream, Bitmap imgChart)
{
float oleWidth = pres.SlideSize.Size.Width;
float oleHeight = pres.SlideSize.Size.Height;
int x = 0;
byte[] chartOleData = new byte[wbStream.Length];
wbStream.Position = 0;
wbStream.Read(chartOleData, 0, chartOleData.Length);
IOleObjectFrame oof = null;
oof = sld.Shapes.AddOleObjectFrame(x, 0, oleWidth, oleHeight, “Excel.Sheet.8”, chartOleData);
oof.SubstitutePictureFormat.Picture.Image = pres.Images.AddImage((System.Drawing.Image)imgChart);
}

but because the file size of my workbook is very high. it gives error on statement
MemoryStream wbStream = workbook.SaveToStream();

Please suggest me, what are the options to export charts, range as image on PowerPoint slide.

thanks



Hi Santosh,

I have observed the query shared by you and it is related to our Aspose.cells team. I am moving this thread to Aspose.Cells forum where our respective team will help you better in this regard. However, for any technical inquiries related to Aspose.Slides, you are always welcome to share the query in Aspose.Slides forum.

Best Regards,

Hi Adnan,

Sorry, I am just posting my concerns, but no one giving concrete answer.

Please solve my issue, so I can complete my previous POC. so I can suggests to my seniors to buy this product.

Regards,
Santosh

Hi Santosh,


In order to find out if the issue is on Aspose.Cells APIs or on Aspose.Slides end, could you please simply separate the issue to only render image from the Excel file chart (when you save to file path) and check the output image if it is still not of the best quality. If the image is of poor quality, kindly do attach your template Excel file (containing the chart) or give us complete sample code (runnable) if you are creating the chart on the fly. Also attach the output image file, we will check it soon.

Regarding the error on the line of code:
e.g
Sample code:
MemoryStream wbStream = workbook.SaveToStream();
Well, SaveToStream is only used if you are saving the file to XLS file format, so if you are saving to XLSX or other advanced MS Excel file format, it won’t be used. To save to XLSX or other advanced file formats, you should use relevant Workbook.Save() overload(s) to save the workbook to memory streams accordingly.

And, to render range (of cells) to image file, please see the document for your reference:
http://www.aspose.com/docs/display/cellsnet/Export+Range+of+Cells+in+a+Worksheet+to+Image

PS. I have also attached our latest version/fix: Aspose.Cells for .NET v16.11.7 (attached), so you should try it first.

Thank you.

Hi Santosh,


Regarding your concerns about the image quality, I have created a sample spreadsheet of my own, and have performed tests using the code snippet provided at the bottom of this post. I believe the EMF generated with Aspose.Cells has good quality, however, when inserted to a presentation slide, the image will be stretched a bit to fit the frame. This is where the problem happens, therefore I would suggest you to generate a bit larger image and reset the scaling as demonstrated below. Please note, setting the ImageOrPrintOptions.HorizontalResolution & VerticalResolution properties is not essential. This is just to get a bigger image of the chart. Please feel free to perform more tests on your side. In case you still face any difficulty, please be kind enough to share the source spreadsheet, EMF generated with Aspose.Cells & the final presentation file. We will perform test on your sample and share our feedback.

C#

var book = new Workbook(dir + “book1.xlsx”);
var sheet = book.Worksheets[0];
var chart = sheet.Charts[0];
chart.ToImage(dir + “output.emf”, new ImageOrPrintOptions()
{
SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias,
ImageFormat = System.Drawing.Imaging.ImageFormat.Emf,
HorizontalResolution = 150,
VerticalResolution = 150
});
var pres = new Presentation();
var slide = pres.Slides[0];
System.Drawing.Image pic = (System.Drawing.Image)new Bitmap(dir + “output.emf”);
var imgx = pres.Images.AddImage(pic);
var PicFrame = slide.Shapes.AddPictureFrame(ShapeType.Rectangle, 50, 50, imgx.Width, imgx.Width, imgx);
PicFrame.RelativeScaleHeight = 1f;
PicFrame.RelativeScaleWidth = 1f;

pres.Save(dir + “output.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);