Groups | Blog | Home
all groups > dotnet interop > august 2006 >

dotnet interop : Getting a date from a cell ( C# )



Shea Martin
8/11/2006 12:05:22 PM
I am reading data in from an XLS file use Excel interop. I currently
get cell data like this:

lRange = lSheet.get_Range( lTopLeftCellName, lBotRightCellName );
Object[,] lValues = (Object[,])lRange.Value2;

The problem is that columns which contain dates (formatted as m/d/y)
come across as floats. i.e., 5/15/2004 comes across as 38122.0.

Is there a way to programmatically know that a cell is formatted as a
date? Is there a way to bring it accross as a DateTime or atleast a
String so I can parse it on my own?

Thanks,

Shea Martin
8/11/2006 1:50:41 PM
[quoted text, click to view]


Using lRange.lRange.get_Value(
Excel.XlRangeValueDataType.xlRangeValueDefault );

insteado fo lRange.Value2 worked.

Cindy M.
8/11/2006 6:50:39 PM
Hi Shea,

Go "the long way around"; use the VALUE property instead of Value2 and
pass it a parameter (you'll need to get the
Excel.xlRangeValueDataType stuff, this is the straight VBA):

Range.Value(xlRangeValueDefault)

[quoted text, click to view]

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)
AddThis Social Bookmark Button