如何解决日期格式excel单元格值 [英] How to resolve a date format excel cell value
本文介绍了如何解决日期格式excel单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在尝试读取日期格式excel单元格,但此读取的结果与我预期的结果不同。例如,如果单元格值为11-dec-2009,则系统返回40158.如何检索正确的值?我检查了openxml返回的datetype但它是null。
任何帮助将不胜感激
谢谢
Hi
I'm trying to read a date format excel cell, but the result of this reading is different that the result i expected. For example, if the cell value is 11-dec-2009 the system returns 40158. How could i retrieve the correct value? I checked the datetype returned by openxml but it's null.
Any help will be appreciated
Thanks
推荐答案
嗨Levimatt,
请注意,ECMA-376中的日期存储为数字值(序列日期)。
Hi Levimatt,
Please be aware that dates in ECMA-376 are stored as numeric values (serial dates).
DateTime oaDate = new DateTime(2009, 12, 11);
double oaValue = oaDate.ToOADate();
Console.WriteLine("Serial value of date 2009-12-11: " + oaValue);
DateTime newDate = DateTime.FromOADate(oaValue);
Console.WriteLine("DateTime of serial date value (40158): " + oaDate);
Console.Read();
以上结果在控制台中显示:
The above results in this in the console:
Serial value of date 2009-12-11: 40158
DateTime of serial date value (40158): 11-12-2009 00:00:00
在.Net-terms 您所体验的东西被称为"OADate"(OLE自动化日期)
我希望这会有所帮助,
:o)
In .Net-terms what you experience is called an "OADate" (OLE Automation Date)
I hope this helps,
:o)
这篇关于如何解决日期格式excel单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文