I have a VSTO addin and I'm reading data from an Excel worksheet.
It seems that almost all numeric data is read as a double. Is it ever possible to get an int value from Range.Value?
Here is some code to demonstrate what I mean.
Worksheet w = (Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.Worksheets["Sheet1"];
var value = ((Range)w.Cells[1, 1]).Value;
bool isInt = value is int;
bool isDouble = value is double;
No matter which format I use in worksheet Sheet1, cell A1, isInt always comes back false.
Is there some format I should be using to get int? I thought maybe General or 0 would work, but it seems not.
Numeric values returned by Range.Value are doubles (possibly becuase they are all stored as doubles in Excel, a number looking like an integer or not is the result of formatting)
The only ints that I have seen coming through GetValue are the ErrorCodes for errors
e.g.
Govert is correct in saying that Excel never stores numbers as an integers.
Excel stores numeric values as Double Precision Floating Point numbers, or as you know Doubles for short.
Doubles are 8-byte variables that can store numbers accurate to approximately 15 decimal places.
EDIT:
Since you are looking for a link, see this
Link: http://support.microsoft.com/kb/78113
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With