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

Exporting gridview not using the carriage returns in cells

2 Answers 3 Views
This is a migrated thread and some comments may be shown as answers.
Deasun
Top achievements
Rank 1
Veteran
Deasun asked on 13 Mar 2020, 01:04 PM

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 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Mar 2020, 10:10 AM

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.
0
Deasun
Top achievements
Rank 1
Veteran
answered on 16 Mar 2020, 12:14 PM

Thank you.

That worked great.

 

Asked by
Deasun
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Deasun
Top achievements
Rank 1
Veteran
Share this question
or