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

Free Support Forum - aspose.com

Embedding ZIp and png files in Excel

Hi Team,

I have purchased Apose Total Licence of version:
17.9.0.0

I have implemented functionality to embed attachments in Excel file.
However, I am not able to open the zip files and png files and jpeg files when embedding in Excel sheet. FOllowing code snippet is used.

finalExcel.Worksheets(sheetName).OleObjects.Add(14, 3, 40, 80, imageData)
finalExcel.Worksheets(sheetName).OleObjects(0).ObjectData = objectData
finalExcel.Worksheets(sheetName).OleObjects(0).Text = sheetName
finalExcel.Worksheets(sheetName).OleObjects(0).DisplayAsIcon = True
finalExcel.Worksheets(sheetName).OleObjects(0).HeightInch = 0.64
finalExcel.Worksheets(sheetName).OleObjects(0).WidthInch = 0.78
LoggingManager.LogInformation(“Ole Objected embeded”, “”)
finalExcel.Worksheets(sheetName).OleObjects(0).DisplayAsIcon = True
finalExcel.Save(excelName, Aspose.Cells.SaveFormat.Xlsx)

@Ritu_Bhola,

Thanks for the code segment and details.

I have tested your scenario/ case using the following sample code (please refer to it), it works fine and I can open the zipped archive when I clicked on the Ole object icon/image in Excel sheet in the output file. Please make sure that you have set the correct path for the zipped archive file or image file when using the “OleObject.ObjectSourceFullName”. Also, see the screenshot for your reference.
e.g
Sample code:

Workbook workbook = new Workbook();
            //Get the first worksheet.
            Worksheet sheet = workbook.Worksheets[0];
            //Define a string variable to store the image path.
            string ImageUrl = "e:\\test\\school.jpg";
            //Get the picture into the streams.
            FileStream fs = File.OpenRead(ImageUrl);
            //Define a byte array.
            byte[] imageData = new Byte[fs.Length];
            //Obtain the picture into the array of bytes from streams.
            fs.Read(imageData, 0, imageData.Length);
            //Close the stream.
            fs.Close();
            //Get zip file path in a variable.
            string path = "e:\\test2\\Report90043.zip";
            //Get the file into the streams.
            fs = File.OpenRead(path);
            //Define an array of bytes.
            byte[] objectData = new Byte[fs.Length];
            //Store the file from streams.
            fs.Read(objectData, 0, objectData.Length);
            //Close the stream.
            fs.Close();
            sheet.OleObjects.Add(0, 0, 40, 40, imageData);
            //Set embedded ole object data.
            sheet.OleObjects[0].ObjectData = objectData;
            sheet.OleObjects[0].FileFormatType = FileFormatType.Unknown;

            sheet.OleObjects[0].HeightInch = 0.64;
            sheet.OleObjects[0].WidthInch = 0.78;
            sheet.OleObjects[0].DisplayAsIcon = true;
            sheet.OleObjects[0].ObjectSourceFullName = path;

            
            //Save the excel file
            workbook.Save("e:\\test2\\outMyFile12.xlsx");

Hope, this helps a bit.
sc_shot1.png (78.9 KB)

Which version of Aspose you are using?
I am also having similar code

But not able to open for png and zip files.

@Ritu_Bhola,

I am using latest version/fix. Please try using latest version/fix and if you still find any issue with latest version (e.g Aspose.Cells for .NET v20.3.x), kindly do provide sample code (runnable) and sample file(s) to reproduce the issue, we will check it soon.

WHich is your aspose version?

@Ritu_Bhola,

Aspose.Cells for .NET v20.3.

Hi Amjad,

Can you me how to upgrade Aspose from lower version.

Do I need to install it first?

Is there an step by step tutorial for the same?

@Ritu_Bhola,

You may refer to Release notes section of different releases to know more about what is changed in the APIs for your reference:
https://docs.aspose.com/display/cellsnet/Release+Notes

There is nothing special for upgrading to latest version. You may use the newer Aspose.Cells.Dll (adding reference to it and replacing/removing older version in your project), see the document for your reference:
https://docs.aspose.com/display/cellsnet/Installation

PS. Your current subscription might be expired to use latest versions of Aspose.Cells, so, you would also need to upgrade your subscription as well.

ok…
Your current subscription might be expired to use latest versions of Aspose.Cells, so, you would also need to upgrade your subscription as well. How to change the subscription?

And what about licence file?

@Ritu_Bhola,

For all licensing/subscription queries, please post in Aspose.Purchase forum. One of our sales staff member will help you soon there.