Images get distorted after added in an excel workbook using template file

We are creating an excel file using an existing template.
We add an image to a new sheet in this template. After
saving excel file, image looks distorted. The original
size is not retained.

We used following code snippet:

{
//Use the image file attached - Motor_Adaptor
FTA_INCH_complete_Section View.2.png
Image im = Image.FromFile(“Motor_Adaptor
FTA_INCH_complete_Section View.2.png”);
MemoryStream imageData = new MemoryStream();
im.Save(imageData, ImageFormat.Png);


//Use the template file attached
Workbook sampleWorkbook = new
Workbook(“AS9102.xlt”);
Worksheet sampleWorkSheet =
sampleWorkbook.Worksheets[sampleWorkbook.Worksheets.Add()];

sampleWorkSheet.Pictures.Add(1, 1, imageData);
/Provide the path to save the output file
sampleWorkbook.Save(“outputUsingTemplate.xls”);


//without using template file
Workbook sampleWorkbook2 = new Workbook();
Worksheet sampleWorkSheet2 =
sampleWorkbook2.Worksheets[0];
sampleWorkSheet2.Pictures.Add(0, 0, imageData);
sampleWorkbook2.Save(“outputWithoutUsingTemplate.xls”);
}



In file ‘outputWithoutUsingTemplate.xls’ created from
default workbook which has an image with correct
(original) aspect ratio. However file
‘outputUsingTemplate.xls’, generated using attached
template has an image with incorrect width and height.


Can you please let us know what is wrong with this
implementation? Is there any problem with the template? Or
Is there any setting in the template file which needs to
get configured before creating an excel?

Please find attached image and output xls excel files and
templates.

Hi,


Thanks for the template files and sample code.

After an initial test, I observed the issue as you mentioned by using your sample code with your template Excel file and image file. I found that the Image gets distorted after added in an Excel workbook using your template file. If we add the image to a new Workbook instead of existing template file, it works fine and the image is rendered correctly.
e.g
Sample code:

//Use the image file attached - Motor_Adaptor FTA_INCH_complete_Section View.2.png
Image im = Image.FromFile(“Motor_Adaptor FTA_INCH_complete_Section View.2.png”);
MemoryStream imageData = new MemoryStream();
im.Save(imageData, ImageFormat.Png);

//Use the template file attached
Workbook sampleWorkbook = new Workbook(“AS9102.xlt”);
Worksheet sampleWorkSheet = sampleWorkbook.Worksheets[sampleWorkbook.Worksheets.Add()];
sampleWorkSheet.Pictures.Add(1, 1, imageData);
/Provide the path to save the output file
sampleWorkbook.Save(“outputUsingTemplate.xls”);

//without using template file
Workbook sampleWorkbook2 = new Workbook();
Worksheet sampleWorkSheet2 = sampleWorkbook2.Worksheets[0];
sampleWorkSheet2.Pictures.Add(0, 0, imageData);
sampleWorkbook2.Save(“outputWithoutUsingTemplate.xls”);

I have logged a ticket with an id “CELLSNET-44277” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,


Please try our latest version/fix: Aspose.Cells for .NET v8.7.1.3

We have fixed your issue “CELLSNET-44277” now.

Let us know your feedback.

Thank you

Hello,

We have evaluated this fix and issue seems to be resolved. Thank you for your support.
Also we would like to bring it to your attention that when we open the output excel file in Open Office, the images look distorted.
We did not find this behavior with Microsoft Excel and hence we would like to close this issue.

Regards

Hi,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved in Microsoft Excel with the latest fix. We have now closed this ticket. You may post your other issue in a separate thread if you want us to look into it. We will investigate it and fix it if possible.