Take the 2-minute tour ×

I generate an XML file through C#, and the relevent part looks like this

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

However it displays in excel as a number , like 41249 that bears no resemblence to the original date. If I right click the cell, and change the format to dd/MM/yyyy or whatever, then it displays the correct date. Anyone know how I can set the format in the XML for how the date is displayed? The data is there, it's just being displayed incorrectly.

share|improve this question

1 Answer 1

up vote 12 down vote accepted

In the <Styles> section add

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

then mark your cell with the style:

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

Alternatively, open your XML file in Excel, make the change you want, re-save it as XML, then look to see what changed.

share|improve this answer
Sweet, this works great. Unfortunately my excel won't save in xml, it comes up with an error message about schemas, or Excel crashes. I would love to know how to enable Filters by default in the XML to allow column sorting too. –  SLC Jan 13 '10 at 16:03
Wow, I managed it just by adding <AutoFilter x:Range="R4C1:R4C6" xmlns="urn:schemas-microsoft-com:office:excel"> </AutoFilter> to the end. –  SLC Jan 13 '10 at 16:08

Your Answer


