This is a migrated thread and some comments may be shown as answers.

Radgrid excel export : <BR> to new line

3 Answers 145 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Prabeesh
Top achievements
Rank 1
Prabeesh asked on 14 Nov 2012, 03:05 PM
I am facing an issue with Radgrid while exporting to excel. The <BR> tag not creating a new line in the excel instead it take it as a BR text. Please help

3 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 19 Nov 2012, 09:16 AM
Hi Prabeesh,

Could you specify which export method you are using? If you are using ExcelML then instead <br> tag you should use "&#10", because that is the code for the new row. The following code snippet demonstrates how you could replace the <br> tags into the excel document.
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
    e.ExportOutput = e.ExportOutput.Replace("&lt;br /&gt;", "&#10;");
}

All the best,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Prabeesh
Top achievements
Rank 1
answered on 26 Dec 2012, 05:06 PM
Thank You.
Above solution worked but along with the word wrap style.
Add style in ExcelMLExportStylesCreated
     Telerik.Web.UI.GridExcelBuilder.StyleElement StyleElement = new Telerik.Web.UI.GridExcelBuilder.StyleElement();
            StyleElement.Id = "brstyle";
            StyleElement.AlignmentElement.Attributes["ss:WrapText"] = "1";

and apply it for the cell in the ExcelMLExportRowCreated event

  CellElement cElement = e.Row.Cells.GetCellByName("Total Sales");
                cElement.StyleValue = "wstyle";
0
Support
Top achievements
Rank 1
answered on 01 May 2014, 10:25 AM
If your using the Biff Excel format to avoid the Excel error on opening the Excel file, you can use this solution.  Add OnBiffExporting="grid_OnBiffExporting" client side and the method below server side.

protected void grid_OnBiffExporting( object sender, GridBiffExportingEventArgs e )
{
   foreach ( Cell cell in e.ExportStructure.Tables[ 0 ].Cells ) {
      cell.Value = cell.Text.Replace( HTML_BREAK_ROW, string.Empty );
   }
}

private const string HTML_BREAK_ROW = "<BR>";
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Prabeesh
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Prabeesh
Top achievements
Rank 1
Support
Top achievements
Rank 1
Share this question
or