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
125
No Line Breaks in Exported Grid
posted

I'm using NetAdvantage 10.1. In an UltraGrid I have one cell that contains multiple items formatted to appear on multiple lines within the cell. The content looks like this

Item 1<br />Item 2<br />Item 3<br />

That works great and appears like it should on the screen.

Since Excel doesn't recognize the HTML <br />, I use the CellExporting event to replace it with CR/LF. Unfortunately, this doesn't work. I've tried multiple variations (just CR, just LF) with no luck. Somewhere in the process the CR/LF gets replaced with a single space character so the exported cell contents end up like this

Item1 Item 2 Item 3

Does anyone know a workaround for this?

Parents
No Data
Reply
  • 19693
    posted

    Hello Rob,

    You can replace the <br/> tag with new line (\n) inside the CellExporting event

    using the following code snippet:

    if (collumnIndex == 1)

            {

     

                if (e.GridRow != null)// null if the cell is in the header

                {

                    e.Value = e.Value.ToString().Replace("<br/>", Environment.NewLine);

                }

            }

     Inside the CellExported you have to set the format of the cell's collumn and row, for example :

        protected void UltraWebGridExcelExporter1_CellExported(object sender, Infragistics.WebUI.UltraWebGrid.ExcelExport.CellExportedEventArgs e)

        {

            int collumnIndex = e.GridColumn.Index;

     

            if (collumnIndex == 1)       

            {         

               e.CurrentWorksheet.Columns[e.CurrentColumnIndex].Width = 2000;

               e.CurrentWorksheet.Columns[e.CurrentColumnIndex].CellFormat.WrapText = ExcelDefaultableBoolean.True;

     

                if (e.GridRow != null) // null if the cell is in the header

                {

                    int rowIndex = e.GridRow.Index;              

                    e.CurrentWorksheet.Rows[rowIndex].Height = -1;

                }

            }     

        }

    Please let me know if you need further assistance regarding this.

Children