Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
-
Upload
abhijeet-b -
Category
Documents
-
view
221 -
download
0
Transcript of Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
-
7/31/2019 Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
1/6
9/12 Converting a List of Data to XML using Microsoft Excel 2003 - CodeProject
ww.codeproject.com/Articles/14201/Converting-a-List-of-Data-to-XML-using-Microsoft-E
8,929,015 members and growing!Email Password Sign in Join Lost password?
Home Articles Quick Answers Discussions Zones Features Help! The Lounge Search site
Article Browse Code Stats Revisions Alternatives 19
Languages C / C++ Language General
Licence
First Posted 23 May 2006Views 92,433
Bookmarked 47 times
Converting a List of Data to XML usingMicrosoft Excel 2003By Mike Ellison | 23 May 2006 | Article
XML Windows Visual-Studio Dev Intermediate
A tutorial on using XML maps in Excel to convert spreadsheet data to XML.
See Also
More like thisMore by this author
4.66 (23 votes)
Download sample files - 2.58 Kb
Introduction
Microsoft Excel 2003 supports XML in a variety of ways. One application of this XML functionality is theability to export a list of data to an XML format. This is particularly useful when working with data
originally in comma-separated value files (.csv files) or fixed-width data files. Both are plain text file
formats, and are common import/export options for database and spreadsheet applications.
Normally, an XSL stylesheet would be considered when transforming a data source to an XML output. An
XSL stylesheet will not help us transform .csvor fixed-width data into XML however, as XSL requires anXML-based source. A .csvor fixed-width file is easily imported into Excel though, and with a few
additional steps, may be exported to an XML format of choice.
An Excel list becomes exportable to XML when assigned anXML map. An XML map is an XML schema or
other file showing an example of the desired XML output, in which c ase Excel c an infer the schema.Either is associated with the spreadsheet containing the list data. The user then may perform drag-and-
drop operations to connect individual data fields from the map to the list source. Finally, the data is
exported with a menu command.
Step-by-step
The starting point for this task is straightforward: Excel is open, and you have either entered or imported
a list of data (e.g., a .csvfile). Include a heading row, identifying field names at the top of each column.For practice, you may use the file Sample.xls which may be downloaded with the link at the top of this
article.
Hot News: Signs that you're a goodprogrammerThe Code Project Insider. Freeeach morning.
Related Articles
Converter for Microsoft Project2002 XML file to TODOLIST XML file
Convert Excel to XML file/XMLSchema, and validate Excel againsXML Schema
Fetching Data from Microsoft Excelusing SQL
Excel Add-in for Exporting Data toXML
Save data to Excel file usingMicrosoft Excel
List Control Data B inding using XM
-
7/31/2019 Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
2/6
9/12 Converting a List of Data to XML using Microsoft Excel 2003 - CodeProject
ww.codeproject.com/Articles/14201/Converting-a-List-of-Data-to-XML-using-Microsoft-E
1. We will begin by creat ing the map file, which can be either an XML schema or a file showingexample XML output. Open Notepad or your desired text editor.
2. Enter and save the map file. For practice, you may use the file sectionsMap.xmlthat c omes withthe article download. In this illustration, we are creating an example XML document that
demonstrates the output we wish to achieve rather than use a schema. Excel will read the
example output and infer a schema appropriate for the map.
For the example output, create a root element. Nested within the root, create an element that isassociated with a single row of data in the list. The individual fields of data in the list row may be
identified as attributes of that element, or as child elements of the parent.
Once the element representing a full list row is complete, copy and paste it as a second element
within the root. It is important that the example output imply multiple elements to assoc iate with
multiple list rows. The picture below shows the tag repeated twice deliberately; this
allows Excel to infer that it will repeat throughout the list of data.
If the tag were not repeated in the example output, Excel would treat its association
as a single cell of data rather than a column of cells. Repeating the element in the
example allows Excel to infer an assoc iation to the column across multiple rows.
3. In Excel, with the sheet containing your list of data ac tive, choose the menu Data -> XML -> XML
Source. The XML Source task pane opens.
Restoring Two-Way Synchronizatioon SharePoint Lists Using Excel
Using C# and Open XML SDK 2.0for Microsoft Office to Create anExcel 2007 Document
WordML Templates Editor datavisualization using Office 2003WordML features
A Very Easy to Use Excel XMLImport-Export Library
Generate Excel files without usingMicrosoft Excel
Convert your Data to ExcelSpreadsheet
How To Set An Appointment UsingMicrosoft Office Outlook 2003
Excel Report from Microsoft Projec
Write Data to Excel using C#
Exporting Data to Excel
Excel Converter To Microsoft SQLSERVER
Convert XML data to object andback using serialization
ExcelML Templates Editor datavisualization using Office 2003SpreadsheetML features
Microsoft Office XML formats,defective by design?
-
7/31/2019 Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
3/6
9/12 Converting a List of Data to XML using Microsoft Excel 2003 - CodeProject
ww.codeproject.com/Articles/14201/Converting-a-List-of-Data-to-XML-using-Microsoft-E
4. In the XML Source task pane, click theXML Maps button.
5. In the XML Maps dialog, clickAdd..., and select the schema or XML example output file youcreated in step #2. If you are using an XML example rather than a schema, like the
sectionsMap.xmlfile from the article downloads, you will see the following dialog, which you maydismiss by clicking OK:
6. In the XML Maps dialog, the map file will be added. Click OKto dismiss the dialog.
7. The XML Source t ask pane will now display the map elements and at tributes.
-
7/31/2019 Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
4/6
9/12 Converting a List of Data to XML using Microsoft Excel 2003 - CodeProject
ww.codeproject.com/Articles/14201/Converting-a-List-of-Data-to-XML-using-Microsoft-E
This is a good time to verify Excels interpretation of the example output. Each of the icons in the
XML map describes the interpretation of the given element or at tribute.
(source: Excel Help)
The picture above shows that the element in our example output file has been
interpreted as a repeating parent element. The repeating aspect of this interpretation isnecessary to correlate with repeating rows of list data. The elements children are the individual
fields of data across a given row.
8. Now, its time to assoc iate an individual child element or attribute in the map with its list column inthe source. Do this by clicking and dragging a field from the map to the list column header to whichit should be associated. When dropped on the column header, the list column will highlight and is
automatically converted to an Excel List object.
9. Repeat the drag-and-drop operation for each additional field, associating each field in the map with
its respective column of list data by dropping it on top of the column header.
-
7/31/2019 Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
5/6
9/12 Converting a List of Data to XML using Microsoft Excel 2003 - CodeProject
ww.codeproject.com/Articles/14201/Converting-a-List-of-Data-to-XML-using-Microsoft-E
10. With the XML assoc iations made, it is time to export the data. Choose the menu Data -> XML ->Export and specify the location/filename to create the new XML file.
11. Open the newly created file in Notepad or another text editor to verify that the export has workedas desired.
Summary
A list of data in Excel, such as that which may be obtained from a .csvor fixed-width data file, may beexported to an XML format, provided an XML map has been assigned to the spreadsheet. An XML map
may either be an XML schema desc ribing the source data, or an XML document showing an example ofthe desired output format. In an example output f ile, a parent element is defined to correlate with a
given list row. The parent element is repeated at least once in the example output, allowing Excel to
infer its assoc iation to repeated rows in the list. Individual child attributes and elements may then beassociated with respective list columns through a drag-and-drop operation, connecting the XML child to
its related list field header. With the XML map in place and field items associated to columns of data, thedata may be exported with the menu command Data -> XML -> Export. When converted to XML, the list
data is then suitable for use as a source in an XSL transformation or any other XML application.
License
This article has no explicit license attached to it but may contain usage terms in the article text or the
download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
About the Author
Mike Ellison
United States
I work for the University of Nevada, Las Vegas in the Office of Institutional
Analysis and Planning. Among other things, our office is c harged with themission of deriving useful information in support of administrative decision-
making from institutional data. Within the context of t hat mission, my office
mates and I apply technology in the form of custom data processingapplications, data extraction and analysis tools, reporting tools, relational
databases, OLAP solutions, data warehousing, and data mining.
Visit my blog at MishaInTheCloud.com
-
7/31/2019 Converting a List of Data to XML Using Microsoft Excel 2003 - CodeProject
6/6
9/12 Converting a List of Data to XML using Microsoft Excel 2003 - CodeProject
ww.codeproject.com/Articles/14201/Converting-a-List-of-Data-to-XML-using-Microsoft-E
Article Top
Sign Up to vote Poor Excellent Vote
Search this forum Go
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.1206 04.1 | Last Updated 23 May 200 6
Article Copyright 2006 by Mike Ellison
Everything else Copyright CodeProject, 1999-201 2
Terms of Use
Member
Comments and Discussions
You must Sign In to use this message board. (secure sign-in)
Profile popups Noise Medium Layout Normal Per page 25 Update
Refresh FirstPrevNext
aashish30 21:18 27 Feb '12
thewazz 11:23 20 Jan '12
v3ks 11:55 25 Apr '11
priyanka.pardeshi 23:10 17 Nov '10
Mike Ellison 5:49 18 Nov '10
Jagan_nathan_V 5:58 8 Jun '09
Mike Ellison 8:14 8 Jun '09
rkapl5:07 9 Jan '07
Leniel 20:22 29 Dec '06
Mike Ellison 6:35 2 Jan '07
edwoofer 3:37 25 Oct '06
Mike Ellison 13:31 6 Nov '06
edwoofer 6:43 24 Oct '06
Mike Ellison 7:04 24 Oct '06
Cal Schrotenboer 20:13 6 Jun '06
Mike Ellison 5:44 7 Jun '06
ff_lee7 13:44 30 May '06
NoSpamNsk 9:17 31 May '06
Mike Ellison 5:25 2 Jun '06
Last Visit: 18:00 31 Dec '99 Last Update: 1:32 9 Jun '12 1
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Layout: fixed | fluid
Nice Article but one doubt
My vote of 5
My vote of 5
Excellent
Re: Excellent
Excellent one
Re: Excellent one
Generating XML in Excel (and other environments) withoutlimitations
Excellent clarification
Re: Excellent clarification
Time notation without frames
Re: Time notation without frames
closure of tags
Re: closure of tags
XML Attributes vs. Elements
Re: XML Attributes vs. Elements [modified]
excellent article for beginner-----thanks
Re: excellent article for beginner-----thanks
Re: excellent article for beginner-----thanks