Excel XML, how can I get Excel to display the DateTime field in yyyy-MM-dd format?

I am creating an XML file through C # and the relevant part looks like

<ss:Cell>
    <ss:Data ss:Type="DateTime">2009-01-18T00:00:00.000</ss:Data>
</ss:Cell>

However, it is displayed in excel as a number, for example 41249, which does not resemble the original date. If I right-click on a cell and change the format to dd / MM / yyyy or something else, then the correct date will be displayed. Does anyone know how I can set the format in XML to display the date? There is data, it just does not display correctly.

+5
source share
1 answer

In the section, <Styles>add

  <Style ss:ID="s22">
   <NumberFormat ss:Format="yyyy\-mm\-dd"/>
  </Style>

then mark the cell with the style:

<Cell ss:StyleID="s22"><Data ss:Type="DateTime">2009-01-21T00:00:00.000</Data></Cell>

XML Excel, , XML, , .

+16

All Articles