Reading a date from xlsx using open xml sdk

前端 未结 7 1642
长情又很酷
长情又很酷 2020-12-14 01:25

I have a date in format \"4/5/2011\" (month/day/year) in a xlsx file in one of the cells. Im trying to parse the file and load those data in some classes.

So far the

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 01:41

    Open XML stores dates as the number of days from 1 Jan 1900. Well, skipping the incorrect 29 Feb 1900 as a valid day. You should be able to find out algorithms to help you calculate the correct value. I believe some developers use DateTime.FromOADate() as a helper.

    Also, the Cell class has the DataType property as Number by default. So if it's null, it's a number, which includes dates in our case.

    You only go to the shared strings table when the date stored is before the epoch (1 Jan 1900 in this case). And then in that case, the CellValue of the Cell class holds the index to the shared string table.

提交回复
热议问题