Hi, I have a program that generated XML file and this file should be opened with Calc. But this program for date cells sets as type=String, so all date data are imported as “String” and when sorting the date data in column they are sorted alphabetically instead of date. The are currently sorted 01.01.2018 (dd.mm.yyyy), then 02.02.2018 and then 03.01.2018. You notice first and last are from January and second one is February. They are sorted by string, not the actual date.
The cause of the problem is date cells are set as String.
<Cell><Data ss:Type="String">21.1.2009</Data></Cell>
I need something like Type=“Date” but it looks it does not exists. The closes think that I found on web is the following:
Excel XML, how can I get Excel to display my DateTime field in yyyy-MM-dd format? - Stack Overflow which suggest to add new Style and then add this style definition in Cells.
<Styles>
<Style ss:ID="myDateStyle">
<Font ss:Color="#FF0000"/>
<NumberFormat ss:Format="yyyy-mm-dd"/>
</Style>
</Styles>
and then after reference on it:
<Cell ss:StyleID="myDateStyle"><Data ss:Type="DateTime">2009-01-21</Data></Cell>
but date is imported as number (I intentionally added red color in style to see if style is acceped):
Note: First column appears to have a valid date, but it has single quote character in front of it, so it is string not date.
Bellow is whole document. Download it and save it as samle.xls and open it with text editor. I have added three empty lines when relevant part of code appears and three empty line after it, to easily recognize the relevant part of code.
The whole document:
sample.xls
I should somehow define date field is “Data” data type with ‘yyyy-mm-dd’ definition, but can’t figure it out how. Everything I test it always opens as number. How to define a cell to be displayed as Date data field.
P.S. If in Calc I manually right click and select “Format Cells” and select Category=Date and in “Format code” write: DD.MM.YYYY date field is correctly displayed as 21.01.2009.