Save Workbooks as XML

In Excel 2003, you can now save a workbook as an XML spreadsheet or as XML data from the Save As dialog box (Figure 3-1).


Saving as XML makes your workbook usable from non-Windows platforms and convertible to other interesting formats, such as HTML. It’s also handy to understand the little trick Microsoft uses to make Excel’s XML appear as a workbook in Windows.

Save As dialog box

Figure 3-1. Save As dialog box

How to do it

Choosing the XML Spreadsheet file type saves the workbook in an XML file that uses the Microsoft Office schema. Choosing the XML Data file type saves the workbook file in an XML file that uses a schema you provide through an XML map. Since it’s a good idea to start simply, I’ll discuss the XML Spreadsheet format here and the XML Data format later in “Use XML Maps” later in this chapter.

If you save a workbook as an XML spreadsheet, you can open the file in Notepad, edit it, and still reopen/edit it in Excel later—provided you haven’t broken any of the rules in the file’s schema. A simple default workbook includes a lot of items that aren’t required by the Office schema, and you can simply delete those items to see the simplified “core” of an XML spreadsheet, as shown in the following XML:

 <?xml version="1.0"?> }- Processing instruction <?mso-application progid="Excel.Sheet"?> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" } xmlns:o="urn:schemas-microsoft-com:office:office" ...

Get Excel 2003 Programming: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.