I have an issue with changes to header captions made in HeaderRowExporting event not reflecting in the exported excel file.
exportControl.XLSExport.HeaderRowExporting += new Infragistics.WebUI.UltraWebGrid.ExcelExport.HeaderRowExportingEventHandler(XLSExport_HeaderRowExporting);
void XLSExport_HeaderRowExporting(object sender, Infragistics.WebUI.UltraWebGrid.ExcelExport.HeaderRowExportingEventArgs e)
{
// unindent child headers for xls export
if (e.CurrentOutlineLevel > 0)
e.CurrentColumnIndex = 0;
FormatHeadersForExport(e.Band, ExportType.Excel);
}
private void FormatHeadersForExport(UltraGridBand band, ExportType exportType)
if (band.Index == 0)
foreach (UltraGridColumn col in band.Columns)
switch (col.Key)
case "EstNavPerShare":
case "NavPerShare":
case "EstimatedEndingBalance":
case "EndingBalance":
col.Header.Caption = Regex.Replace(col.Header.Caption, "<span.*", "");
break;
The headerRowExporting handler fires, and I see the caption being renamed, yet the excel document output doesn't have this change. Frustrating. Btw, the same code works for PDF exporter.
Hi cs3145,
I'm glad things worked out for you. I tested your approach with modifying the headers prior to exporting and it works beautifully.
Please contact me if you need more help.
Best Regards,
Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://ko.infragistics.com/support
Hi Petar,
Thanks for the response.
There were a couple of problems with this approach for me:
1. I am hiding some columns from the grid so I can't reference the excel column headers
using the grid column index as you have done. I can probably hack my way around this, but I shouldn't have to.
2. The formatting for the header column thus modified is lost.
However, I was able to find a solution. I am modifying the header caption now just prior to calling Export on the Excel exporter. Probably had something to do with timing - maybe the export control is snapshotting the grid before the headerexporting event completes executing. Making it synchronous seems to work.Thanks,
Chandra
Hi cs31415,
Changing the exported headers is possible using the WebGridExcelExporter. The differences that you have spotted in the ways that the Excel and PDF exporters handle their events are largely related to the differences in the exported formats themselves.
In order to change the headers in the exported file, you should handle the HeaderRowExported event of the Excel exporter. An example alteration of the headers in this event's handler might look similar to:
protected void UltraWebGridExcelExporter1_HeaderRowExported(object sender, Infragistics.WebUI.UltraWebGrid.ExcelExport.HeaderRowExportedEventArgs e) { for (int i = 0; i < UltraWebGrid1.Columns.Count; i++) { e.CurrentWorksheet.Rows[0].Cells[i].Value = "Column" + i; } }
Please contact me if I can be of further assistance.
Best Regards,Petar IvanovDeveloper Support EngineerInfragistics, Inc.http://ko.infragistics.com/support