Introduction
ExcelExportXML is a Microsoft Excel 2010 Add-in that generates XML data from excel sheet. It is developed in Visual Studio 2010 using C#.
It is a very simple add-in. To understand how to works, consider an excel sheet having following data.
Country | Capital | Continent |
France | Paris | Europe |
Germany | Berlin | Europe |
India | New Delhi | Asia |
Indonesia | Jakarta | Asia |
Using the add-in, above can be exported to following Xml.
<sheet1> <row> <country>France</country> <capital>Paris</capital> <continent>Europe</continent> </row> <row> <country>Germany</country> <capital>Berlin</capital> <continent>Europe</continent> </row> <row> <country>India</country> <capital>New Delhi</capital> <continent>Asia</continent> </row> <row> <country>Indonesia</country> <capital>Jakarta</capital> <continent>Asia</continent> </row> </sheet1>
Once the Add-in is installed, you will have a ‘Generate XML’ button on Add-ins tab of Excel Ribbon as shown below. Clicking ‘Generate XML’ will pop up the save file dialog which will allow you to save the generated Xml file.
Use Case & Assumptions
ExcelExportXml is useful when you have tabular data in excel and the first row contains the column headings. It works based on following assumptions.
- First row is considered as column headers and will be converted to Xml tags.
- After encountering the first empty cell in header row, rest of the columns to the right will be ignored.
- Supports columns up to ‘Z’ only i.e. maximum of 26 columns.
- First row for which all values are empty will be considered the end of sheet.
- Sheet name and column names should not have any spaces.
Why not use standard Save As Xml functionality
Excel provides more than one ways to export xml data. One of them is ‘Save As Xml Data’ available in Save As dialog. This requires Xml Mappings to be defined which I believe requires developer Add-in from Microsoft to be installed.
Another option is ‘Save As Xml Spreedsheet 2003’ which generates following Xml.
<Worksheet ss:Name="Sheet1"> <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="5" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15"> <Column ss:Width="51"/> <Column ss:Width="54"/> <Column ss:Width="51.75"/> <Row ss:StyleID="s64"> <Cell><Data ss:Type="String">Country</Data></Cell> <Cell><Data ss:Type="String">Capital</Data></Cell> <Cell><Data ss:Type="String">Continent</Data></Cell> </Row> <Row> <Cell><Data ss:Type="String">France</Data></Cell> <Cell><Data ss:Type="String">Paris</Data></Cell> <Cell><Data ss:Type="String">Europe</Data></Cell> </Row> <Row> <Cell><Data ss:Type="String">Germany</Data></Cell> <Cell><Data ss:Type="String">Berlin</Data></Cell> <Cell><Data ss:Type="String">Europe</Data></Cell> </Row> <Row> <Cell><Data ss:Type="String">India</Data></Cell> <Cell><Data ss:Type="String">New Delhi</Data></Cell> <Cell><Data ss:Type="String">Asia</Data></Cell> </Row> <Row> <Cell><Data ss:Type="String">Indonesia</Data></Cell> <Cell><Data ss:Type="String">Jakarta</Data></Cell> <Cell><Data ss:Type="String">Asia</Data></Cell> </Row> </Table> </Worksheet>
As you can see, the above might not be what you want. It is more a representation of excel sheet than semantics of your data. ExcelExportXML is quite limited but effective in a common scenario where you have tabular data and the first row contains column headers.
Updated the ExcelXMLExport:
– Unlimited number of columns are supported. Earlier this was limited to A-Z.
– Test the Add-in on latest version of Microsoft Office i.e. 2013. It works fine.
– Uploaded the code at http://github.com/umaranis/ExcelXMLExport