I opened *.htm file with Excel Application (Microsoft.Office.Interop.Excel). It was parsed excellent! So I can work with it. For more speed, I’m trying to get data from Excel Range and insert into System.Array and work with it:
Excel.Range range = ExcelWorksheet.get_Range("A1", "H1500"); // get all values
System.Array dataArray = (System.Array)(range.Cells.Value2); // insert into array
Problem is with data type. If Excel cell has time or date format, range.Cells.Value2 makes:
12.06.2012 to 41072 (Excel Cell Type – date)
14:48 to 0,616666666666667 (Excel Cell Type – time)
If I get single value form Excel Cell, I get correct value (with Cells.Text.ToString()):
ExcelWorksheet.get_Range("A1", "A1").Cells.Text.ToString()
Task: I need get values from Excel Sheet as they are, just like text, not as another type.
And don’t want Excel thinks instead of me 🙂
Why don’t you just convert the returned values to the format you need? The FromOADate method of DateTime is designed for this (see http://msdn.microsoft.com/en-us/library/1ad4d8d6(v=vs.80).aspx). For example, the time value returned represents a fractional portion of a 24 our day. Hence the following example will output “14:48”:
As far as the date values, you can use the same approach. The only difference will be the fact that the value from Excel (double) would be greater than zero because it is includes a date portion (not just time). The following will yield “12.06.2012”:
To further illustrate, in the case that you are dealing with date AND time (returned Excel value is greater than zero), the following will yield “6/12/2012 2:48:00 PM”: