I'm trying to export a grid that has an image column to PDF.
I'm currently using the CellExporting Event to try add the image.
protected void dExporter_CellExporting(object sender, DocumentCellExportingEventArgs e) { if (!e.IsHeaderCell && !e.IsFooterCell && !e.IsSummaryCell) { if (e.GridCell.Column.Key == "ImageUrl") {
// Remove Html Tags var url = e.GridCell.Text; var startPos = url.IndexOf("\"") + 1; var endPos = url.LastIndexOf("\""); url = url.Substring(startPos, endPos - startPos); e.ReportCell.AddImage(new Infragistics.Documents.Graphics.Image(url)); } } }
The issue I am having is that e.ReportCell is always null.How do I initialize this so that I can format the ReportCell, or should I be trying to do this in a different way
Hi Paul,
With the next Service Release, it should be fixed so that the cells are no longer null and you could manipulate them. If this is not the case, please let us know so that we can fix it.
regards,David Young
Hi,
I have a similar problem, I have a couple of html tags in my grid that i'm trying to remove during the export to avoid the end user from seeing html code. Seems for some strange reason the cell that contains html tags is null during the OnCellExported and OnCellExporting events, my code:
protected void WebDocumentExporter1_CellExporting(object sender, DocumentCellExportingEventArgs e) { try { if ((!e.IsHeaderCell) && (!e.IsFooterCell) && (!e.IsSummaryCell)) //Check to get items cells { if (e.ExportValue != null) { string cellValue = e.ExportValue.ToString(); //.WorksheetCell.Value.ToString(); //get cell value bool flagComplete = false; while (!flagComplete) { if ((cellValue.Contains("<")) && (cellValue.Contains(">"))) //check if has html content { int begPoint = cellValue.IndexOf("<"); //begining point of html tag int endpoint = cellValue.IndexOf(">") + 1; //end point of html tag cellValue = cellValue.Remove(begPoint, (endpoint - begPoint)).Replace("\r\n", " ").Trim(); //remove html tag flagComplete = false; //keep flag false incase there is another html tag } else { //ensure all unncessary white spaces are removed cellValue = cellValue.Replace(" ", " ").Trim(); cellValue = cellValue.Replace(" ", " ").Trim(); cellValue = cellValue.Replace(" ", " ").Trim(); e.ExportValue = cellValue; //if no html tags were found then replace old cell value with new cell value flagComplete = true; //set flag to true cause no html tags where found } } } else {
string p1 = string.Empty; } } } catch (Exception ex) {
} }
This is a bug, you can submit it to our support system.
Currently I can suggest you to handle the RowExported event and manipulate the cell from there:
void WebDocumentExporter1_RowExported(object sender, DocumentRowExportedEventArgs e) { if (!e.IsHeaderRow && !e.IsFooterRow && !e.IsSummaryRow) { System.Reflection.PropertyInfo property = e.ReportRow.GetType().GetProperty("Cells"); IList cells = property.GetValue(e.ReportRow, null) as IList;
// Get the desired cell by index ITableCell reportCell = cells[0] as ITableCell;
reportCell.AddImage(new Infragistics.Documents.Graphics.Image(url)); } }
I hope that this workaround does the job for you!