开发者

how to get the earliest date Excel support programmatically

Excel AddIn, C#, UDF, MyUDF calls a web service to retrieve certain date. Sometimes the date returned is not in range of Jan-1-1900 to Dec-31-9999 (Excel Date Range). E.g. in one case returned date is Jan-2-0002 (valid in C# but not valid in Excel), then Excel crashes. I do not hard code 开发者_StackOverflow社区"Jan-1-1900", so wonder if there is a way that I can get it programmatically. thanks


Inside Excel, convert the date corresponding to 1 into a string that you can parse:

=TEXT(1,"dd-mm-yyyy")

which should give you 01-01-1900 or 02-01-1904 depending on the date system chosen (hat tip to barrowc!). Note how the date systems don't only differ by four years but also by the fact that in one case the value 1 corresponds to January 1st (in 1900) and in the other it is 0 which corresponds to January 1st (in 1904). For a given Workbook, the Workbook.Date1904 Property can tell you which date system is being used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜