Exporting gridview not using the carriage returns in cells

3 posts, 0 answers
  1. Deasun
    Deasun avatar
    33 posts
    Member since:
    May 2019

    Posted 13 Mar Link to this post

    I have a gridview that displays fine in the app.

    Cells with multiple values show up as:

    Value 1

    Value 2

    Value 3

     

    Within the cell.

    But on exporting the grid the cells value is all on one row within the cell.

    How to get the exported excel sheet to look like what is displayed on the apps grid.

    This is what I am currently setting in code:

     objGrid.BestFitColumns();
    spreadExporter = new Telerik.WinControls.Export.GridViewSpreadExport(objGrid)
                                {
                                    ExportVisualSettings = true,
                                    SheetName = strSheetName,
                                    FileExportMode = Telerik.WinControls.Export.FileExportMode.NewSheetInExistingFile
                                };
    exportRenderer = new Telerik.WinControls.Export.SpreadExportRenderer();

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3958 posts

    Posted 16 Mar Link to this post

    Hello, Deasun, 

    In order to keep the new lines in the cells values, you can handle the CellFormatting event of the SpreadExportRenderer and enable the text wrapping:

            public RadForm1()
            {
                InitializeComponent();
    
                this.radGridView1.Columns.Add("Col");
                this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
                this.radGridView1.Rows.Add("First"+Environment.NewLine+"Second"+Environment.NewLine+"Third");
    
                this.radGridView1.AutoSizeRows = true;
    
            }
    
            private void radButton1_Click(object sender, EventArgs e)
            {
                string fileName = @"..\..\" + DateTime.Now.ToLongTimeString().Replace(":", "_") + ".xlsx";
                GridViewSpreadExport spreadExporter = new Telerik.WinControls.Export.GridViewSpreadExport(this.radGridView1)
                {
                    ExportVisualSettings = true, 
                    FileExportMode = Telerik.WinControls.Export.FileExportMode.NewSheetInExistingFile
                };
                SpreadExportRenderer exportRenderer = new Telerik.WinControls.Export.SpreadExportRenderer();
                spreadExporter.CellFormatting+=spreadExporter_CellFormatting;
                spreadExporter.RunExport(fileName, exportRenderer);
                Process.Start(fileName);
            }
    
            private void spreadExporter_CellFormatting(object sender, Telerik.WinControls.Export.CellFormattingEventArgs e)
            {
                e.CellStyleInfo.TextWrap = true;
            }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Deasun
    Deasun avatar
    33 posts
    Member since:
    May 2019

    Posted 16 Mar in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thank you.

    That worked great.

     

Back to Top