2

In code behind, the following code will export the RadGrid data to an Excel file, but all the text has been wrapped.

RadGrid1.ExportSettings.ExportOnlyData = True            
RadGrid1.ExportSettings.IgnorePaging = True
RadGrid1.MasterTableView.ExportToExcel()

enter image description here

If I manually select all the data and then click the "Wrap Text" button to disable wrapped text, the data seems good.

enter image description here

How can I disable the wrap function during export?

DanM7
  • 2,203
  • 3
  • 28
  • 46
Joe Yan
  • 2,025
  • 8
  • 43
  • 62

1 Answers1

1

You need to attach the event for when the Excel styles are created in your RadGrid's definition:

OnExcelMLExportStylesCreated="rgdReport_OnExcelMLExportStylesCreated"

Then in the code behind method, disable the WrapText attribute:

Protected Sub RadGrid1_ExcelMLExportStylesCreated(source As Object, 
    e As Telerik.Web.UI.GridExcelBuilder.GridExportExcelMLStyleCreatedArgs)
    For Each style As Telerik.Web.UI.GridExcelBuilder.StyleElement In e.Styles
        style.AlignmentElement.Attributes.Add("ss:WrapText", "0")
    Next
End Sub

Check out this forum post and this blog for more info.

DanM7
  • 2,203
  • 3
  • 28
  • 46