Click here to Skip to main content
11,922,559 members (32,490 online)
Click here to Skip to main content
Add your own
alternative version


53 bookmarked

Excel Add-in for Exporting Data to XML

, 21 Jan 2015 CPOL
Rate this:
Please Sign up or sign in to vote.
ExcelXMLExport is a Microsoft Excel 2010 / 2013 Add-in that generates XML data from Excel sheet.


ExcelExportXML is a Microsoft Excel 2010/2015 Add-in that generates XML data from an Excel sheet. It is developed in Visual Studio using C#.

It is a very simple add-in. To understand how it works, consider an Excel sheet having the following data.

Country Capital Continent
France Paris Europe
Germany Berlin Europe
India New Delhi Asia
Indonesia Jakarta Asia

Using the add-in, the above can be exported to the following XML.

        <capital>New Delhi</capital>

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 the following assumptions:

  1. The first row is considered as column headers and will be converted to XML tags.
  2. After encountering the first empty cell in header row, rest of the columns to the right will be ignored.
  3. Supports columns up to 'Z' only, i.e., maximum of 26 columns.
  4. The first row for which all values are empty will be considered the end of the sheet.
  5. The sheet name and column names should not have any spaces.

Why Not Use Standard Save As XML Functionality

Excel provides more than one way 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 the 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>
   <Cell><Data ss:Type="String">France</Data></Cell>
   <Cell><Data ss:Type="String">Paris</Data></Cell>
   <Cell><Data ss:Type="String">Europe</Data></Cell>
   <Cell><Data ss:Type="String">Germany</Data></Cell>
   <Cell><Data ss:Type="String">Berlin</Data></Cell>
   <Cell><Data ss:Type="String">Europe</Data></Cell>
   <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>
   <Cell><Data ss:Type="String">Indonesia</Data></Cell>
   <Cell><Data ss:Type="String">Jakarta</Data></Cell>
   <Cell><Data ss:Type="String">Asia</Data></Cell>

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.

Writing Add-in for Microsoft Excel 2010

Using Visual Studio 2010 Professional, creating Excel Add-in is pretty simple. Following are the steps I followed for ExcelExportXml:

Step # 1

Create a new project of type 'Excel 2010 Add-in'. The project will have a class file called ThisAddin.cs.

Step # 2

For creating a button on the Excel ribbon, right click on the project and select Add - > New Item.

Step # 3

Select 'Ribbon (XML)' from the list of new items and name the ribbon class, say Ribbon1. This will add two files to the project which are Ribbon1.cs and Ribbon1.xml.

Step # 4

Add the following code in ThisAddin class:

protected override Microsoft.Office.Core.IRibbonExtensibility
     return new Ribbon1();

Step # 5

In Ribbon1.xml, define the properties of the button that will be displayed on the Excel ribbon. The onAction attribute specifies the method which will be called from Ribbon1.cs on clicking the button (onAction="OnTextButton").

<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns=
      <tab idMso="TabAddIns">
        <group id="MyGroup"
               label="Export XML">
          <button id="textButton" label="Generate XML"
             screentip="Export to XML" onAction="OnTextButton"
             supertip="Export excel sheet to XML file."/>

Step # 6

Add the following method declaration to Ribbon1.cs and implement your functionality here.

public void OnTextButton(Office.IRibbonControl control)
    //TODO:Add your implementation here


  • 21st January, 2015: Limit of number of columns removed. Unlimited number of columns can be exported now.
  • 7th December, 2011: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Syed Umar Anis
Software Developer (Senior)
United Arab Emirates United Arab Emirates

You may also be interested in...

Comments and Discussions

QuestionError during installation: "Could not load assembly Microsoft.Office.BusinessApplications.Fba" - Fix Pin
SiTeW30-Jun-15 15:14
memberSiTeW30-Jun-15 15:14 
AnswerRe: Error during installation: "Could not load assembly Microsoft.Office.BusinessApplications.Fba" - Fix Pin
Syed Umar Anis1-Jul-15 2:47
professionalSyed Umar Anis1-Jul-15 2:47 
SuggestionAttributes instead of Nodes Pin
souitom19-Feb-15 0:41
membersouitom19-Feb-15 0:41 
GeneralRe: Attributes instead of Nodes Pin
Syed Umar Anis22-Feb-15 3:29
professionalSyed Umar Anis22-Feb-15 3:29 
BugOnly reading columns with A-Z Pin
ivek81cro6-Jan-15 16:43
memberivek81cro6-Jan-15 16:43 
GeneralRe: Only reading columns with A-Z Pin
Syed Umar Anis21-Jan-15 1:35
memberSyed Umar Anis21-Jan-15 1:35 
BugError while installation Pin
Member 1122971212-Nov-14 20:32
memberMember 1122971212-Nov-14 20:32 
GeneralRe: Error while installation Pin
Syed Umar Anis13-Nov-14 21:08
memberSyed Umar Anis13-Nov-14 21:08 
GeneralMy vote of 2 Pin
huangyunfeng31-Oct-13 20:07
memberhuangyunfeng31-Oct-13 20:07 
GeneralRe: My vote of 2 Pin
Afzaal Ahmad Zeeshan20-Oct-14 7:07
professionalAfzaal Ahmad Zeeshan20-Oct-14 7:07 
Questionerror while installing Pin
Cool Smith10-Jun-13 2:25
memberCool Smith10-Jun-13 2:25 
QuestionChanging Element names and Line Feeds Pin
xml_man5-Mar-12 11:42
memberxml_man5-Mar-12 11:42 
AnswerRe: Changing Element names and Line Feeds Pin
Syed Umar Anis12-Mar-12 19:50
memberSyed Umar Anis12-Mar-12 19:50 
Questiondo you have this for Excel 2007? on x64? Windows 7? Pin
Tarek Mourad22-Feb-12 14:18
memberTarek Mourad22-Feb-12 14:18 
AnswerRe: do you have this for Excel 2007? on x64? Windows 7? Pin
Syed Umar Anis25-Feb-12 1:41
memberSyed Umar Anis25-Feb-12 1:41 
BugThanks, just what I've been looking for. However.... Pin
Member 860149230-Jan-12 11:04
memberMember 860149230-Jan-12 11:04 
GeneralRe: Thanks, just what I've been looking for. However.... Pin
Runlin Zhang12-Mar-12 12:20
memberRunlin Zhang12-Mar-12 12:20 
GeneralRe: Thanks, just what I've been looking for. However.... Pin
Wayne Loschen4-Aug-12 9:03
memberWayne Loschen4-Aug-12 9:03 
GeneralRe: Thanks, just what I've been looking for. However.... Pin
Syed Umar Anis4-Aug-12 22:41
memberSyed Umar Anis4-Aug-12 22:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151120.1 | Last Updated 21 Jan 2015
Article Copyright 2011 by Syed Umar Anis
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid