I have a column that can contain various data types such as Dates, Strings, Numbers, etc... for instance:
What I need to do is to display this contact on a separate dialog window. The problem is that when I use cell.Value2
I get double instead of the visible string. and when I try to use cell.Value
and after that check if cell.Value.GetType().Name == "DateTime"
the NumberFormat
string doesn't match the C# formatting; for instance, the NumberFormat
I get for the 5th line in the image is m/d/yy;@
which is useless in C# because cell.Value.ToString(formatting)
will result in 0/5/20;@
.
Another problem, the cell that contains time returns 0.43888
in both cell.Value
and cell.Value2
the only way I can see something that can be used is with: cell.Value(XlRangeValueDataType.xlRangeValueMSPersistXML)
or cell.Value(XlRangeValueDataType.xlRangeValueXMLSpreadsheet);
which are time-consuming even before parsing them. Since sometime I need to read hundreds of thousands of values I cant use the XML approach.
Related links: Get Formatted Cell Values efficiently How do I check type of dynamic datatype at runtime? https://social.msdn.microsoft.com/Forums/office/en-US/32163853-7e27-4af7-b95b-f4b53118a594/c-excel-date-issue?forum=vsto
My Question: What is the fastest and most robust way to get the presented values of excel cells into C# objects - without any change to the formatting?