tags:

views:

127

answers:

3

I am reading a cell value from excel using named range in my case sometime the column width is smaller then the value that is present in the cell and hence it is appearing as ##### when it is huge number.

when i read this from csharp it is reading as #####. Any fix for this

Sample code:

Excel.Application.get_Range(strRange, Type.Missing).Text.ToString() //If i make it 
Excel.Application.get_Range(strRange, Type.Missing).Value2.ToString() //and read any date string i get 40390
+3  A: 

Without having any code to read I would guess that you are reading a display string or similar, which Excel will update each time the row width varies.

You probably need to be reading a more raw value.

Ian
yes for now i am read that as .Text instead of .Value2 that is because when i read dates i get integer values is there a way for this??
Sathish
That's because Dates store within Excel are stored as integers. DateTimes are stored as floating point numbers. The format is known as an OLE date. To determine if the value is a date or not you need to check the formatting of the cell too.
Ian
A: 

Are you perhaps trying to import negative dates? Excel doesn't handles these well, processing dates as doubles usually works though.

Lunatik
+1  A: 

.Text gives you whatever you see as formatted in the Excel rendering layer (so #### if the column is too small) .Value2 gives you the underlying Excel value.

Date/times in Excel are stored internally as numbers representing the number of days since Year 1900 Jan 0 plus a decimal part representing a fraction of 24 hours for the time, so your date is coming through as an integer.

If you want to convert the number back into a date you can use Format: for example format(40390,"ddmmyyyy") or format(40390,"dd/mmm/yyyy")

Charles Williams
Or you can convert the double to a date: DateTime date = DateTime.FromOADate(d)
Mathias