Problem with time to string conversion

I reading time values from an Excel file and convert these to strings using the method xls.GetCellValue(row, column).ToString;

Now I have the problem that 9:23:00 is converted to 0.390972222 and not to '9:23:00'. Is there a trick avoid this kind of transformation?

Regards,
Stephan

Hi,

In Excel, there are no date types, only numbers, and so a cell with a Date/Time is just a number that in its real part says the number of fays since 1/1/1900 and in the fractional time says the date (in this case 0.39 = 1/24/3600*(9 * 3600 +23 * 60)

To know if it is a date or a number you need to look at the format of the cell, if it is a date format then it contains a date, if not a number.

But well, in your case, if you want the string as it shows in Excel, then use:
xls.GetStringFromCell(row, column) instead of GetCellValue

GetCellValue returns the unformatted raw value
GetStringFromCell returns the value formatted a Excel will show it.

So for example, if in a cell you have the number 2, and the format is 0.00
GetCellValue will return the floating point number 2.
GetStringFromCell will return the string '2.00'

Please look at the "Reading Files" demo for more information on how you can read dates or numbers from cells and display a date or a number depending in the format of the cell.

Thank you so much Adrian for clarifying. My problem is solved!