We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Image in cell

I'm creating excel document from controller like this:

ExcelExport exp = new ExcelExport();
var DataSource = db.recognitions.Include(c => c.CaptureSource).ToList();

ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Create(1);

IWorksheet sheet = workbook.Worksheets[0];
sheet.FirstVisibleRow = 0;

sheet.Range["A1"].Text = "Capture source";
sheet.Range["B1"].Text = "Date / time";
sheet.Range["C1"].Text = "Plate text";
sheet.Range["D1"].Text = "Country assumed";
sheet.Range["E1"].Text = "Confidence level";
sheet.Range["F1"].Text = "Plate image";

int row = 2;
foreach (var item in DataSource)
sheet.Range[row, 1].Text = item.CaptureSource.name;
sheet.Range[row, 2].Text = item.date.ToShortDateString();
sheet.Range[row, 3].Text = item.plate_text;
sheet.Range[row, 4].Text = item.country_assumed;
sheet.Range[row, 5].Text = item.confidence_level;
sheet.Range[row, 6].Text = item.plate_image_url;


return excelEngine.SaveAsActionResult(workbook, "SpreadSheet.xls", HttpContext.ApplicationInstance.Response, ExcelDownloadType.PromptDialog, ExcelHttpContentType.Excel97);
catch (Exception)

return View("Index");

and it is working file. 
Now, I want to show image from item.plate_image_url in column 6 for all rows. So, every row has its own picture. I can add picture with sheet.Shapes.AddPicture(item.plate_image_url), but how can I place that image centered in cell [row, 6] ?


3 Replies

SS Sridhar Sukumar Syncfusion Team January 9, 2017 12:47 PM UTC

Hi Bernard, 
Thank you for contacting Syncfusion support. 
Images can be placed in a cell and positioned by using TopRow, LeftColumn, Height and Width properties of ShapeImpl class. Please refer the following code example to achieve this. 
Code snippet: 
ShapeImpl shape = (ShapeImpl)sheet.Shapes.AddPicture(item.PlateImageUrl); 
shape.TopRow = row; 
shape.LeftColumn = 6; 
shape.Height = sheet.GetRowHeightInPixels(row); 
shape.Width = sheet.GetColumnWidthInPixels(6); 
We have also prepared a sample as per your code snippet which can be downloaded from the following link. 
Alternative method: 
You can achieve your requirement using template markers in XlsIO. Please refer the following UG documentation link to know about template markers.  
To achieve your requirement, an image object can be maintained instead of image URL. Logic to get images from URL can be added to achieve your requirement using template markers. 
Please let us know if you have any queries. 
Sridhar S. 

BJ Bernard Jurlina January 9, 2017 09:02 PM UTC

Hi Sridhar,

thanks for the example. It was very useful.


SS Sridhar Sukumar Syncfusion Team January 10, 2017 10:19 AM UTC

Hi Bernard, 
You are welcome. 
Sridhar S. 

Live Chat Icon For mobile
Up arrow icon