Add Excel sheet into PowerPoint file

Hi,

I develop ASP.NET application with Visual Studio 2005 (.NET Framework 2)
I’m use Aspose.Cells 5.3.0.0 and Aspose.Slides 5.5.0.0

I need to add an Excel worksheet into a PowerPoint file (only as image or as embedded object + image).
I’m attached the input Excel file (demo.xls) and a empty pptx file (demo.pptx).

This is the code that I used:

Dim presDemo As New PresentationEx(“C:\demo.pptx”)
Dim wBookDemo As New Workbook(“C:\demo.xls”)
Dim msDemo As New MemoryStream
Dim objectFrameDemo As OleObjectFrameEx

wBookDemo.Save(msDemo, SaveFormat.Excel97To2003)
msDemo.Position = 0

objectFrameDemo = presDemo.Slides(0).Shapes.AddOleObjectFrame(0, 0, 500, 350, “Excel.Sheet.8”, msDemo.ToArray)
presDemo.Save(“C:\modified.pptx”, Aspose.Slides.Export.SaveFormat.Pptx)
The issue is the ouput file contais the embedded object, but it’s hidden behind the image with red sentence “EMBEDDED OLE OBJECT” (see attachment wrong.pptx). Also, if I edit the embedded object in pptx file, it becomes very big.

Is there a way to get an output file like the one that I attached (correct.pptx)?

I tried to use the object SheetRender for save an image to use in the OleObjectFrameEx object, but it loses the shades of the colors of the objects contained in the excel sheet, also some information are not properly aligned and last column is missing (see attachment imgFromSheetRender.emf).

Kind regards,

Davide


Hi Davide,

Thank you for sharing the sample files.

Issue # 1: "Embedded Ole Object" message is not an issue with Aspose.Slides but behavior of Ole Frame. The ole frame sets default image showing message, "Embedded Ole Object" when ole frame is not activated. As soon as the Ole frame is activated it retains the image of respective excel sheet. Aspose.Slides with Aspose.Cells facilitates to set the image of respective excel sheet or chart as ole frame image in deactivated stage. Please check the detailed code here and see how ole image can be added as per your requirement.

Issue # 2: Regarding resizing of excel file while opening as Ole object, please check the details here with sample code on how to overcome this issue.

In case you need any further assistance, please do let us know.

Thanks & Regards,

Hi Owais,

Thank you for your reply.
With your advice, I’m solved one problem, the size of the embedded object.

But I don’t understand how to fix that issue of image quality.
Im’ use this code:
imgOption = New Rendering.ImageOrPrintOptions
imgOption.ImageFormat = Imaging.ImageFormat.Emf
imgOption.HorizontalResolution = 200
imgOption.VerticalResolution = 200
wSheet.PageSetup.PrintArea = “A1:” & CellsHelper.ColumnIndexToName(wSheet.Cells.MaxDataColumn) & wSheet.Cells.MaxDataRow + 1

imageStream = New MemoryStream
sheetImage = New Rendering.SheetRender(wSheet, imgOption)
sheetImage.ToImage(0, imageStream)
newObjectFrame.Image = slide.Parent.Images.AddImage(imageStream)
But the image quality is bad, it loses the shades of the colors of the objects contained in the excel sheet, also some information are not properly aligned and last column is missing. You cas see the differences comparing demo.xls with imgFromSheetRender.emf.
I’m need to use the sheet as image and not the chart.

Kind regards,

Davide

Hi Davide,

Thank you for the feedback.

Now, as your reported issue is related to Aspose.Cells, I have asked my colleague from Aspose.Cells team to check the issue and share his feedback with you via this forum thread.

Thanks & Regards,

Hi Davide,

Thanks for using Aspose.

I have created the worksheet image using your source file with the latest version: Aspose.Cells
for .NET v7.6.1.4
and it generated the correct image.

Please download and try the latest version. I used the following code to generate the image. I have attached the output image for your reference.

VB.NET


Dim m_workbook As Workbook = New Workbook(“F:\Shak-Data-RW\Downloads\demo.xls”)

Dim wSheet As Worksheet = m_workbook.Worksheets(0)


Dim imgOption = New Rendering.ImageOrPrintOptions

imgOption.ImageFormat = Imaging.ImageFormat.Emf

imgOption.HorizontalResolution = 200

imgOption.VerticalResolution = 200


imgOption.OnePagePerSheet = True


Dim sheetImage As SheetRender = New Rendering.SheetRender(wSheet, imgOption)

sheetImage.ToImage(0, “F:\Shak-Data-RW\Downloads\demo.out.emf”)



Hi Shakeel,

thank you for your reply.

Now it works much better, but there is still a issue that I can’t fix: the last column is missing in the output image and the output image has an A4 portrait format, while the one you attached is landscape and fitted to the data printed.
To resolve this I had to add the statement “wSheet.PageSetup.Orientation = PageOrientationType.Landscape”. So the last column also appears, but the image is not adapted to the printed data: how do I fit the data to the printed image?

I have attached the source code with the input and output files.
In the attached zip I have included both the output, portrait and landscape.

Kind regards

Hi Davide,

Thank you for writing back.

You may use ImageOrPrintOptions.OnlyArea property for your requirement. Setting this property to true will render only data area on the image canvas, and adjust the orientation accordingly. Please have a look at below provided code snippet and attached output file.

VB.NET


Dim book = New Workbook(myDir & “demo.xls”)
Dim sheet = book.Worksheets(0)
Dim imageOptions = New ImageOrPrintOptions()
imageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf
imageOptions.OnlyArea = True
Dim render = New SheetRender(sheet, imageOptions)
render.ToImage(0, myDir & “output.emf”)

Ok, perfect, thank you very much!
One last thing: there is a way to ensure that the margins and the cells
without color are rendered transparent in the worksheet’s output image?
PowerPoint renders trasparent, while Aspose renders white.

Kind regards,
Davide

Hi Davide,

Thanks for your posting and using Aspose.

Currently, it is not possible to render cells without colors as transparent in the Sheet2Image feature. MS-Excel renders such cells as transparent in PowerPoint while Aspose.Cells renders them as white. However, we have logged a New Feature request in our database for this option. We will look into it and implement it if possible. Once, it is implemented or we have some other news for you, we will let you know asap.

This issue has been logged as CELLSNET-42229.

I have attached a screenshot illustrating this issue for a reference.

Hi Shekeel,

Thank you for your assistence.

Kind regards,

Davide

Hi,

Thanks for using Aspose.Cells for .NET.

We have fixed this issue.

Please download and try this fix: Aspose.Cells for .NET v7.7.0.2.

Please see the following code for your reference.

C#


Workbook wb = new Workbook(srcFile);


var imgOption = new ImageOrPrintOptions();

imgOption.ImageFormat = ImageFormat.Emf;

imgOption.HorizontalResolution = 200;

imgOption.VerticalResolution = 200;

imgOption.OnePagePerSheet = true;

imgOption.Transparent = true;


var sr = new SheetRender(wb.Worksheets[0], imgOption);

sr.ToImage(0, outFile.emf);



The issues you have found earlier (filed as CELLSNET-42229) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Very fast, thank you very much!

regards,
Davide