How to check Excel cell format in C# to see if cell value is a date

萝らか妹 提交于 2019-12-10 00:25:16

问题


Good Morning All!

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

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.

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!

Thanks in advance.


回答1:


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



来源:https://stackoverflow.com/questions/7964230/how-to-check-excel-cell-format-in-c-sharp-to-see-if-cell-value-is-a-date

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!