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

Spreadsheet Cell Values for DateTime returning Number values

11 Answers 4058 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Ed James
Top achievements
Rank 2
Ed James asked on 02 Dec 2013, 07:30 AM
I have a CSV file with Dates ("MM/DD/YYYY"). I wish to parse these values within the active worksheet as string values, but they're converted to number format (i.e. "22532"). I'm unable to get these values in the original string format.

Is it possible to ensure all cell values are in String format, representing exactly how they are in a CSV file?

11 Answers, 1 is accepted

Sort by
0
Svetoslav
Telerik team
answered on 04 Dec 2013, 03:36 PM
Hi Ed,

Thank you for contacting us!

Unfortunately, my attempts to replicate the issue you describe were not successful. Could you please try to import your file in our click-once examples and see if you reproduce the issue there?  Also, please verify Q3 2013 (2013.3 1016) is the version of RadControls for WPF you are using.

In order to analyze the roots of the problem we would need to replicate it on our side. For this reason if the issue persists please send us your project. Once we are able to reproduce the behavior locally, we will do our best to assist you further.

We are looking forward to hearing from you again!

Regards,
Svetoslav
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Jiri
Top achievements
Rank 1
answered on 26 Sep 2014, 01:54 PM
Hi,

I have exactly the same problem as reported by Ed James, except in Silverlight.

var cell = ws.Cells[row, c]; // ws is Worksheet
var val = cell.GetValue();
var v = val.Value.RawValue; // v is now some strange number instead of for instance: 1.1.2014 - what is a value from excel's cell

Could you please do something with that?

Thank you,
Jiri
0
Nikolay Demirev
Telerik team
answered on 29 Sep 2014, 08:57 AM
Hello Jiri,

The date values are stored in the Worksheet as number values with specific number format. This is the reason why when you get the value of the cell the result is number. If you want to get the formatted result, you could use the following code snippet:

CellSelection cellSelection = this.workbook.ActiveWorksheet.Cells[0, 0];
cellSelection.SetValue(22532);
cellSelection.SetFormat(new CellValueFormat("m/d/yyyy"));
  
ICellValue value = cellSelection.GetValue().Value;
CellValueFormat format = cellSelection.GetFormat().Value;
CellValueFormatResult formatResult = format.GetFormatResult(value);
string result = formatResult.InfosText;


Regards,
Nikolay Demirev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Jiri
Top achievements
Rank 1
answered on 29 Sep 2014, 09:47 AM
Hi Nikolay,

Thank you, great, this works nicely!

Cheers,
Jiri

0
Ben
Top achievements
Rank 1
answered on 08 Feb 2017, 07:22 PM

Hi, im using XlsxFormatProvider and CsvFormatProvider to import file into a Workbook. My date format are good when i use an XLSX file (they keep the cell format). But when i import a CSV file, i would like to keep the original format.For example, if i have a CSV:

2017-01-31,info1

01/31/2017,info2

31/01/2017,info3

I would like that telerik import all the date without changing the format. Is it possible ? Because now, it all change them to 2017-01-31.

0
Deyan
Telerik team
answered on 13 Feb 2017, 04:12 PM
Hello Benoit,

Saving spreadsheet data to CSV file ensures preserving only the cell values and all information from other cell formatting features is lost. If you require preserving the date format you should either use XLSX file format or implement custom logic that sets CellValueFormat to specific cells right after the CSV import as mentioned in previous answer by Nikolay Demirev.

Regards,
Deyan
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
ManishB
Top achievements
Rank 1
answered on 28 Mar 2017, 02:49 PM

Hello,

I have the same issue for Date cell in Telerik Web Workbook.

can you please suggest how can I do that for Web workbook cell.

0
Veselin Tsvetanov
Telerik team
answered on 31 Mar 2017, 09:53 AM
Hello ManishB,

May I ask you to provide a bit more details about the scenario in which you use the Telerik.Web.Spreadsheet.dll? Do you have it in ASP.NET Web Forms application with RadSpreadsheet, or you use it in an ASP.NET MVC application? Also, please explain a bit more in detail the actual use case in which you observe this issue.

Regards,
Veselin Tsvetanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
ManishB
Top achievements
Rank 1
answered on 31 Mar 2017, 03:00 PM

Hello Veselin,

I am using Telerik.Web.Spreadsheet.dll with ASP.NET MVC application. I used it to import CSV or TXT file. I am transferring data from Imported file to DataTable, so while retrieving data through worksheet I got (22532) such value from a cell for Date Field and Now I want to convert it to DateFormat and set it to the DataTable.

0
Veselin Tsvetanov
Telerik team
answered on 05 Apr 2017, 06:46 AM
Hello,

Thank you for the additional information provided.

In order to retrieve the correct date, you will need to convert the OLE Date format to DateTime object:
var cell = workbook.Sheets[0].Rows[0].Cells[0];
var value = Double.Parse(cell.Value.ToString());
var date = DateTime.FromOADate(value);

Regards,
Veselin Tsvetanov
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Christopher
Top achievements
Rank 1
Iron
Iron
answered on 15 Nov 2022, 07:44 PM
It would be very nice if there was an option on CsvFormatProvider to read everything in as a string instead of the current behavior. Sure I can use what's suggested in this thread to convert the dates from numbers into the format I want, but that assumes I know which columns are dates. In my use case, I won't know that so in order to get my dates as strings I ended up not using Telerik.Windows.Documents.Spreadsheet and used  Microsoft.VisualBasic.FileIO.TextFieldParser instead.
Nikolay Demirev
Telerik team
commented on 17 Nov 2022, 03:56 PM

Hi Christopher,

I have just tested importing the attached CSV file containing dates in the format "MM/DD/YYYY" while my OS has the same setting for date format, and the RadSpreadsheet shows the values as dates which are also formatted as dated. Could you try it on your end and share the result?

Tags
Spreadsheet
Asked by
Ed James
Top achievements
Rank 2
Answers by
Svetoslav
Telerik team
Jiri
Top achievements
Rank 1
Nikolay Demirev
Telerik team
Ben
Top achievements
Rank 1
Deyan
Telerik team
ManishB
Top achievements
Rank 1
Veselin Tsvetanov
Telerik team
Christopher
Top achievements
Rank 1
Iron
Iron
Share this question
or