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

Export to CSV - empty string or NULL values exported as single space

3 Answers 1243 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg S
Top achievements
Rank 1
Greg S asked on 04 Aug 2016, 11:34 PM

I'm exporting a grid to CSV. I've noticed when a value is null or blank, the resulting value is space. Using <ExportSettings Csv-EncloseDataWithQuotes="true" /> a blank value shows up as " " vs. "".

Is there a setting that can change this behavior? The files are being uploaded to another 3rd party tool, and a single space is not a valid option.

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 09 Aug 2016, 02:34 PM
Hello Greg,

I have tested the behavior in question with our latest version and there is no empty space in the exported CSV file. Can you please test with our latest versions and see if the issue still persists?

Looking forward to your reply.


Regards,
Konstantin Dikov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Greg S
Top achievements
Rank 1
answered on 15 Aug 2016, 06:05 PM

Well - this fixed the empty string problem, but created a new problem.Date data types are being handled differently in the Excel export. After this update, sql columns defined as "datetime" are being exported as numbers. You can reformat the numbers as dates in Excel, but that's a huge hassle to do for multiple columns every time you export. Before this update, users would not have to do this.

Is there a way to configure the radgrid Excel export so it formats dates?

 

 

0
Greg S
Top achievements
Rank 1
answered on 15 Aug 2016, 06:50 PM

I figured it out. 

I was running the code below and changing the formatting of every cell to "@". This is because my page is actually a generic report processor, and if the data started with a character that Excel interpreted as a function (e.g. "-", "+", etc.) then it would cause problems. The previous version of the controls however still exported a date in a date format however. After upgrading to the newest version however, dates were exported as their Excel numeric equivalent. 

protected void radGrid_InfrastructureExporting(object sender, GridInfrastructureExportingEventArgs e)
 {
     foreach (var row in e.ExportStructure.Tables[0].Rows)
         foreach (var cell in row.Cells)
             cell.Format = "@";
 }
I added a check for  a datetime data type before changing the format and this fixed my scenario.

Tags
Grid
Asked by
Greg S
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Greg S
Top achievements
Rank 1
Share this question
or