RADGrid Export to Excel Wrap Text format

3 posts, 1 answers
  1. James
    James avatar
    2 posts
    Member since:
    Apr 2014

    Posted 08 Dec 2016 Link to this post

    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. Answer
    Pavlina
    Admin
    Pavlina avatar
    6187 posts

    Posted 13 Dec 2016 Link to this post

    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.
  3. James
    James avatar
    2 posts
    Member since:
    Apr 2014

    Posted 13 Dec 2016 in reply to Pavlina Link to this post

    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;
            }

Back to Top