如何检查Excel单元格的格式在C#中,看看是否单元格的值是一个日期

问题描述:

早安所有!

我一直在开发一段时间中,用户可以发布一组值的一组日期的项目。

I have been developing a project for some time in which users can publish a set of values for a set of dates.

如用户将在Excel中选择一个范围,其中将包括日期值,以及其中包含的值公布对应于这些日期同样大小的范围。

e.g. The user would select a Range in Excel which would contain date values, and an equally sized Range which contains values to publish corresponding to these dates.

我需要做的( C#)是检查单元格格式的两个区域,看看哪一个是真正的日期,我一直在使用ExcelDNA因为所有日期为双打回来后,我可以在技术上分析我的'价值'为日期,并导致所有各种各样的问题。

What I need to do (C#) is check the cell formatting of both Ranges to see which one is 'actually' a date, I've been using ExcelDNA and since all dates are returned as doubles, I can technically parse my 'values' to dates, and cause all kinds of problems.

如果我能得到的单元格格式,我可以看到小区是否实际上意味着是一个约会!

If I can get the cell formatting, I can see whether the cell is actually meant to be a date!

先谢谢了。

Range.NumberFormat 应该帮助你确定给定格/范围被格式化为日期。如果单元格/范围日期格式然后NumberFormat属性将包含格式字符串,即DD / MM / YYYY

The Range.NumberFormat should help you determine if a given cell/range is formatted to a date. If the cell/range is date formatted then the NumberFormat property will contain the format string, i.e. dd/mm/yyyy