Insert images to cells, how to set the height the same as images?

Posted by Yesi under C# on 4/13/2015 | Points: 10 | Views : 381 | Status : [Member] | Replies : 1
I have to put on one excel sheet many images.
I want to indicate the height of each image and the system should calculate the width automatically. I can?
how can I specify the row height of the excel sheet so that they are as high as the pictures?


Posted by: Million on: 4/13/2015 [Member] Starter | Points: 25

Hey Yesi. Here is a solution you can use a third party too, it's a Excel component . Download a free edition and add reference to your project then use the following code:
Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];

Image img = Image.FromFile("02.png");

CellRange range = ws.Range["A1"];
//Spire.Xls measured the row height with points, not pixels, so I make a conversion here
range.RowHeight = img.Height * 141 / 188;
ws.Pictures.Add(1, 1, img);
wb.SaveToFile("Sample.xlsx", ExcelVersion.Version2010);

Yesi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response