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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Image in cell

Thread ID:

Created:

Updated:

Platform:

Replies:

128204 Jan 7,2017 11:36 PM UTC Jan 10,2017 10:19 AM UTC ASP.NET MVC 3
loading
Tags: XlsIO
Bernard Jurlina
Asked On January 7, 2017 11:36 PM UTC

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;

row++;
}

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

workbook.Close();
excelEngine.Dispose();
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] ?

Thanks!

Sridhar Sukumar [Syncfusion]
Replied On 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. 
 
Regards, 
Sridhar S. 
 


Bernard Jurlina
Replied On January 9, 2017 09:02 PM UTC

Hi Sridhar,

thanks for the example. It was very useful.

Bernard.

Sridhar Sukumar [Syncfusion]
Replied On January 10, 2017 10:19 AM UTC

Hi Bernard, 
 
You are welcome. 
 
Regards, 
Sridhar S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;