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”);
//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.
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.