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

RADGrid Export to Excel Wrap Text format

2 Answers 456 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 09 Dec 2016, 01:09 AM

I have an export to excel where I enter 
 the excel crlf character. All of that works fine but when I open the excel file the column is not formatted to handle crlf and I have to set it to Wrap Text manually. Is there any way to format this column with wrap text?

 

Thanks,

James

2 Answers, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 13 Dec 2016, 05:43 PM
Hello,

To wrap the text of the desired cell you should find the respective cell, set its TextWrap property by hooking OnInfrastructureExporting exporting event and insert the newline character ('\n') wherever you want the text to be wrapped. A sample code which presents header cell text wrapping is attached below:
protected void rgProfile_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
    {
        Telerik.Web.UI.ExportInfrastructure.Table tbl = e.ExportStructure.Tables[0];
  
        var cell1 = tbl.Cells[2, 1];
        cell1.Value = "First line .\nSecond line";
        cell1.TextWrap = true;
       
    }


Regards,
Pavlina
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
James
Top achievements
Rank 1
answered on 13 Dec 2016, 07:17 PM

That worked perfectly. I then set my column width and every row in the column to wrap

 

       Telerik.Web.UI.ExportInfrastructure.Table tbl = e.ExportStructure.Tables[0];
        tbl.Columns[2].Width = 225;
        for (int i = 1; i <= tbl.Rows.Count; i++)
        {
            var cell1 = tbl.Cells[2, i];
            cell1.TextWrap = true;
        }

Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
James
Top achievements
Rank 1
Share this question
or