Images (Charts- Others) Lost when saving from Excel 2003 to Excel 2007 (xlsx) and Vice Versa

Hi,

We faced problems of Images (lie Charts,Jpeg) lost when we save the Opened Excel file 2003 to Excel 2007 xlsx format and vice -versa while saving an opened excel file 2007 (xlsx file) to xls file (2003) . In Both the case the Images are Lost.

Please let me know what is the problem and how to fix it. we used Aspose.Cells .NET Version

Regards,

Barani

Hi,

Thank you for considering Aspose.

We have tested your mentioned issues, but we were unable to find any problem.

Please note that if you save the workbook as 2003 file format (or any other format)and after that you are saving the same workbook object again in the 2007 file format (without reopening the workbook), it will save nothing. Because after saving the first file the workbook object has been emptied and it contains null. Now, after first save, if you want to perform any manipulation (save it to other formats etc.), either you have to reopen the workbook or before saving the file first time, you have to use workbook.Copy() method to copy the workbook object.

If you still face any problem, please provide us sample code & your template file so we can further test your issue.

Thank You & Best Regards,

Hi ,

Thanks for the quick Response.

Its true that my program also works if the images are like JPEG.(just tried it out !).

But the actual file which my program shd be applied to Images which is of *.EMF type.

so please take any *.EMF Images and embed it in the sheet and try it out. I think while conversion

it failes. Certainly I am not in a position to share the .EMF Image that I have

Hi guys,

Additional Info

Even the JPG,EMF works only when they are inserted as Insert --> Picture Option.

But if they are embeded using the Insert --> Object (OLE) even BMP, Visio , EMF

Aspose fails.

Hope to get feedback on this.

Hi,

Thank you for considering Aspose.

Please try the attached latest version of Aspose.Cells. I think you are using some older version that is why you are having this problem.

Following is my sample test code which worked fine with the attached version of Aspose.Cells.
Sample Code:

//Instantiate a new Workbook.

Workbook workbook = new Workbook();

//Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

//Define a string variable to store the image path.

string ImageUrl = @"C:\img.emf";

//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 an excel file path in a variable.

string path = @"f:\excels\input.xls";

//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();

//Add an Ole object into the worksheet with the image

//shown in MS Excel.

sheet.OleObjects.Add(14, 3, 200, 220, imageData);

//Set embedded ole object data.

sheet.OleObjects[0].ObjectData = objectData;

//Save the excel files

Workbook wb = new Workbook();

wb.Copy(workbook);

workbook.Save(@"c:\tstoleobjects.xls");

wb.Save(@"c:\tstoleobjects.xlsx",FileFormatType.Excel2007Xlsx);

Thank You & Best Regards,

Hi,

Thanks for the Update.

True, Assembly Version of the Aspose.Cell which I had was 4.5.1.0

from XLS -- > XLSX Now with this new Assembly it is workfing perfectly ...

from XLSX -- > XLS still I am not able to save OLE Objects with this Assembly .

Also refer to the attached Sample Code..

using System;

using System.IO;

using System.Collections.Generic;

using System.Text;

using Aspose.Cells;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

String fn = "d:/barani/test1.xlsx";

String dn = "d:/barani/test2.xls";

Workbook test = new Workbook();

test.Open(fn);

Worksheet sht1 = test.Worksheets[0];

Cells celarr = sht1.Cells;

celarr["A1"].PutValue ("Test Data");

//test.Save(dn, FileFormatType.Default);

//test.Save(dn, FileFormatType.Excel2007Xlsx);

Workbook cpy = new Workbook();

cpy.Copy(test);

//cpy.Save(dn, FileFormatType.Excel2003);

cpy.Save(dn, FileFormatType.Default);

//cpy.Save(dn, FileFormatType.Excel2007Xlsx);

}

}

}

Thanks and Regards,

Barani

Hi,

Thanks for providing us the details.

We will look into your issue. We appreciate if you could post your template .xlsx file(s) here, it will also help us in figuring out the issue (involved) more accurately.

Thank you.

Hello,

Thanks for the reply. We are working on creating a test template for sharing. At the moment you can create a .xlsx file with images as embedded objects inside it. Then convert and save the file to .xls format. This results in loss of images, but converting .xls to .xlsx works fine.

Our motivation here is to treat .xlsx file as .xls file without any loss of data. If you can give some example that would be useful.

Thanks.

Hi,

Please try our latest release (4.6.0):

http://www.aspose.com/community/files/51/file-format-components/aspose.cells/entry156149.aspx
it will support your need.

Thank you.

Hi,

We just installed the latest version and tested. Unfortunately .xlsx when converted and saved to .xls images were not present in the file.

Regards,

Gopal.

Hi Gopal,

Could you post your template file(s) with sample code here, we will check it soon.

Thank you.

Hi Amjad,

Sorry that it is taking time to share the template. I have to get permissions before i share.

When i insert an image using Insert picture or Insert object option it works fine and conversion works. The problem is that we have images inserted using our custom application on a machine where the software is installed, in our developer machines the same software is not installed. This means when we double click on the image from excel itself, it says "Cannot start the source application of this object". This is exactly our scenario and for this the conversion from .xlsx to .xls fails, but for same scenario the conversion from .xls to .xlsx works. If you can reproduce this scenario it would be helpful. Anyhow i will try to get you a dummy template soon.

Best Regards,

Gopal.

Hi,

Thank you for considering Aspose.

Please try the attached latest version of Aspose.Cells. We have fixed the following issue,

'OleObject could not be opened after converting Excel2007 xlsx to Excel2003 xls file’.

Thank You & Best Regards,

Hi,

We have fixed the bug i.e.., OleObject could not be opened after converting Excel2007 xlsx to Excel2003 xls file. Please try the attached version.

Thank you.

Hello,

I just copied the new dll and tried. Unfortunately, the conversion from .xslx 2007 to .xls 2003 did not have any images. Earlier and even now, conversion of 2003 file to 2007 format works fine and images are also present in .xlsx file when converted.

The error in my case was "Cannot start source of the object when clicked on the image in excel". I am still working on getting you the sample template file. Sorry for the delay.

Best Regards,

Gopal.

Hello,

My sample code is below. A very simple one.

String fn = "C:/Test1.xlsx";

String dn = "C:/Test2.xls";

Workbook test = new Workbook();

test.Open(fn);

Worksheet sht1 = test.Worksheets[0];

Cells celarr = sht1.Cells;

celarr["D1"].PutValue ("TestValue");

Workbook cpy = new Workbook();

cpy.Copy(test);

cpy.Save(dn, FileFormatType.Excel2003);

Hi,

Thank you for considering Aspose.

Well, we have implemented your scenario but we are unable to get any problem. Please share your template file, so we can figure out the problem.

Thank You & Best Regards,

Hello,

Please find the sample template file for your tests. With the latest libraries provided yesterday, i tested the following and these are the results. (Version - 4.6.0.5)

1) .XLSX to .XLS (2007 to 2003 format) - Images are lost

2) .XLSX to .XLSX (Just writing some values and saving in 2007 format itself) - Images are lost

Attachment: Input.xlsx (File to be used), Output.xls (Result of my test)

Regards,

Gopal.

Hi,

Thank you for providing the template files.

After an initial test, we were able to reproduce the issue you have mentioned. We will fix it and get back to you soon.

Thank You & Best Regards,

Hi,

Thank you for considering Aspose.

Please try the attached latest fix of Aspose.Cells. We have fixed the issue regarding the OleObjects.

Thank You & Best Regards,