There is a cell in the Excell document. It has a date. Cell value 43017.559872685182

If you open a document in Excell and see the format of this cell, there will be a date. BUT!

cell.DataType is then null. My searches led me to the information that cell.DataType not null only if it is SharedString or Boolean . Next you need to look at cell.StyleIndex.Value

The format is calculated from it.

 CellFormat cellFormat = (CellFormat)wbPart.WorkbookStylesPart.Stylesheet.CellFormats.ElementAt((int)cellStyle); 

I also found a description of the formats. (I do not remember the link, but here are several values ​​for memory)

14 - short date 165 - long date 164 - monetary (Currency)

And I get a cell format 164. But there is a date in it! How so?

How can I understand that I am dealing with a date?

UPD:

I also found the string value of the cell format.

 string format = wbPart.WorkbookStylesPart.Stylesheet.NumberingFormats.Elements<NumberingFormat>() .Where(i => i.NumberFormatId.ToString() == cellFormat.NumberFormatId.ToString()) .FirstOrDefault()?.FormatCode; 

For a date cell, this is "dd / mm / yy \ h: mm; @". But what to do with it, I do not know. Do not rely on Regex in this matter.

  • Comments are not intended for extended discussion; conversation moved to chat . - PashaPash

0