c# - Casting Range.Value2 of Excel interop to string -


i import values excel sheets in c# application. 1 column text can contain values. used following:

range range = ... // getting excel, works fine string mystring = (string)range.value2; 

when cell contains text, working. when contains, example, 123, debugger shows 123.0 range.value2 , conversion string fails exception.

i wonder, how write general conversion kinds of cells. @ least string , integer, may float content.

i found solution may not nice works:

mystring = range.value2 == null ? "" : range.value2.tostring(); 

may better exists.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -