Many StackOverflow posts and other online forums have questions similar to this, but none of them really resolve the issue I’m having.
I’m exporting an XML file from Excel. The Excel file contains dates. In the XML file, however, those dates show up as integers–the date is made to be the nth day since 1/0/1900, I believe.
I’m using JavaScript to extract the data from the XML file to populate a table in a web page.
I suspect that a solution could come in two different forms:
1. A way to convert, in JavaScript, the integer to the date it represents.
2. A way to force the XML file to take a formatted date from the Excel file.
I’m clearly a novice with XML and JavaScript, so your assistance would be sincerely appreciated. Thanks.
The format Excel uses for the xml-export depends on the added XML-schema. This can be explicitly created and added or — as I suspect in your case — has been implicitly/ automatically generated by Excel.
In my example I have two colums, the first one has via XML-Schema to format date-time, the second is normal text and only for the representation in Excel (column format) a date.
When I export this as XML I get two seemingly completely different results:
When I check the XML-Schema (e.g. with “Debug.Print ActiveWorkbook.XmlMaps(1).Schemas(1).XML”) I see the difference (only snippet, not the complete file):
The first column is in the schema of format datetime, the second is varchar. Again, you might not even be aware, how Excel handles your XML-data, since this schema is automatically generated (if I recall correctly in Excel 2003 there was a message indicating that an schema had benn generated for you)
Now how to acomplish this — especially in an existing file: I would try to extract the XML-Schema (see above), save it as something.xsd, adapt the schema according to your needs and import this new Schema. Bummer is you have to set the mapping again (or try this: Excel 2007 XML Source Maps – Refreshing Schemas). Often I let MS Access generate my XML-Schema, i.e. generate the required table, insert some values and exprt the table as XML (ticking the option to add the schema).
I hope this general outline gives you an idea on how to proceed.
Regards
Andreas