C # Excel Reader converts timestamps to decimal

When I use Excel Reader, it reads everything perfectly except for timestamps. He turns, for example, 15:59:35 in .67290509259259268

How can i stop this?

object[,] valueArray = (object[,])excelRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);

This is my array, which stores the values ​​that are read from the excel sheet. Not sure if this is the reason.

+3
source share
2 answers

Try it DateTime.FromOADate- however, the numerical value indicated in the question does not actually correspond to the time you specified.

+2
source

The reason for this is because Excel saves all DateTimes as floating point numbers. The decimal part is the time component, and the integer part is the date.

Range.Text , , . , , ( , ). , , ( - v.slow).

, FlexCel - , , .

( , get_Value, [,]).

if (excelRange!= null)
{
   int nRows = excelRange.Rows.Count;
   int nCols = excelRange.Columns.Count;
   for (int iRow = 1; iRow <= nRows; iRow++)
   {
      for (int iCount = 1; iCount <= nCols; iCount++)
      {
         excelRange= (Microsoft.Office.Interop.Excel.Range)xlSheet.Cells[iRow, iCount];
         String text = excelRange.Text;
      }
   }
}

(Edit: , Sharepoint.)

+2

All Articles