We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert excel file into excel as an Oleobject issue

Hi!
Adding normal plain excel files, works fine.
but, I'm having problem adding complex excel file (that contains sheets and formulas) into a worksheet.
I don't get any exception generating an excel file with aspose .Cell, and the result did display an image icon of ole obj, but it does not embed any object.
please refere to the file attached, tstoleobjects.xlsx. The other file is the one I tried to add into.
Thank you~

Hi,

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue by executing the following sample code using the latest version: Aspose.Cells
for .NET v8.5.2.2
. The code embeds your source excel file into the output workbook but it makes the output workbook corrupt.

We have logged this issue in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43871 - Embedding source excel file as OLE object corrupts the output excel file

I have also attached the output excel file generated by the code for a reference.

C#

string imgFile = @“D:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Blue hills.jpg”;


string xlsxFile = @“F:\Shak-Data-RW\Downloads\CFSI_CMRT4-00.xlsx”;


byte[] binaryImg = File.ReadAllBytes(imgFile);

byte[] binaryXlsx = File.ReadAllBytes(xlsxFile);


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];


int idxOle = worksheet.OleObjects.Add(4, 4, 200, 200, binaryImg);


OleObject objOle = worksheet.OleObjects[idxOle];


objOle.DisplayAsIcon = true;

objOle.FileFormatType = FileFormatType.Xlsx;

objOle.ObjectData = binaryXlsx ;

objOle.ProgID = “Worksheet”;

objOle.ObjectSourceFullName = “source.xosx”;


workbook.Save(@“output.xlsx”);

Hi,

Thanks for using Aspose.Cells.

We have looked into this issue further and found that this is not the bug of Aspose.Cells.


It should be the limitation if an encrypted file could not be inserted as an OLE object in MS Excel.


And if “Protect Workbook” is selected, the file will be encrypted with default password before Excel 2007 and Aspose.Cells.



There are two solutions:



a) Re-save the file in Excel 2010 or above version



b) Re-save the file with Aspose.Cells with the following codes:



Workbook w = new Workbook(xlsxFile);


MemoryStream ms = new MemoryStream();


w.Settings.IsDefaultEncrypted = false;


w.Save(ms, SaveFormat.Xlsx);


byte[] binaryXlsx = ms.ToArray();