Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
520
UltraWebGrid ExcelExporter HeaderRowExporting event issue
posted

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.  

Parents
  • 49378
    posted

    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 Ivanov
    Developer Support Engineer
    Infragistics, Inc.
    http://es.infragistics.com/support

Reply Children