Digital Survivors
 

Quick XML Formatting with Microsoft Excel

Scott Manning
July 14, 2005 | Comments (6)

You have a long list that you want to put in an XML format. This tutorial will show you a quick way to do it with Microsoft Excel.

For this example, I have a list of the Fortune 100 companies and their locations. You can download (Right-click and "Save As") the list and following along the tutorial.

QuickXMLFormattingwithMicrosoftExcel_clip_image002.jpg

I want to take this list and put it in the following XML format:

<fortune100>
<company>
<name></name>
<location></location>
</company>
</fortune100>

In two empty columns, I'm going to put the opening and closing tags for the names of the companies.

QuickXMLFormattingwithMicrosoftExcel_clip_image004.jpg

In a third empty column, I'm going to put in an Excel formula that will display Wal-Mart Stores, Inc. inside the tags. The formula I used is =C1&A1&D1. In layman's terms, this formula is going to display the contents of cells C1, A1, and D1 in that order.

QuickXMLFormattingwithMicrosoftExcel_clip_image006.jpg

The result of the formulas is as follows.

QuickXMLFormattingwithMicrosoftExcel_clip_image008.jpg

The next thing we want to do is create the same formula for the entire list of companies. By selecting cells C1, D1, and E1, and then left-clicking the bottom right-hand corner of cell E1, I can drag my mouse down and apply the contents/formulas of the selected cells to the cells below them.

QuickXMLFormattingwithMicrosoftExcel_clip_image009.gif


QuickXMLFormattingwithMicrosoftExcel_clip_image010.gif

Do this for your entire list.

You're not done yet. Since column E is dynamically generated from a formula, you need to get actual list of what the formulas are producing.

Select column E and copy it. With Column E still selected, click the arrow to the right of the Paste icon on the toolbar and select "Values".

QuickXMLFormattingwithMicrosoftExcel_clip_image011.gif

This will paste the actual values of the formulas into the column. You can then cut-n-paste this column into whatever editor you use to edit XML files.

Column C and D can be deleted. Repeat this process for the location and you're done applying XML formatting using Excel.

QuickXMLFormattingwithMicrosoftExcel_clip_image013.jpg

Thanks to Steve DiBello for showing me this quick and dirty trick.

Advanced Method
Patrick H contributed the following quicker method:

="<company><name>"&A5&"</name><location>"&B5&"</location></company>"


Enjoy this article? There's more. Digital Survivors is a source of articles, tutorials, reviews, and commentary on all things digital.

Stay informed with rss, our feed is permanently ad-free.

These articles are new:

bullet Valkyrie
bullet 1940 Aircraft Production Figures
bullet Let Teachers Carry Concealed Firearms at Schools
bullet 50 Books on World War II Recommended by John Keegan

If you don't immediately see what you want, you can start a topic in our forums.

 



Comments (6):
1) Posted by: Patrick H
July 14, 2005 6:22 PM

Instead of adding the tags to their own colum, you can save a lot of space doing this... =""&A5&""&B5&"".... where you just add strings to the equation, and those strings are the tags you want to add.


2) Posted by: patrick H
July 14, 2005 6:23 PM

Ok, that didn't exactly show up properly. I'm guessing its stripping tags. I'll email you the code.


3) Posted by: Scott Manning
July 14, 2005 6:34 PM

Patrick, I see exactly what you're saying. I'll add it to the tutorial.


4) Posted by: Ben Jackson
July 14, 2005 7:49 PM

If you have an editor that allows column typing like Primalscript (Windows) or TextMate (Mac), you can do the same thing without Excel. If you have one of these editors and don't know how to do this, find out how. It's one of the greatest timesavers ever.


5) Posted by: Tony
July 15, 2005 9:30 AM

That is one way of doing it, a much cooler way is with Excel 2003 XML Mappings...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_xl2003_ta/html/Office_Excel_XML_Toolbox.asp


6) Posted by: phil
December 17, 2005 1:14 PM

I wouldn't waste my time on a PC or learning anything microsoft.

make a tab-delimited text file with the data then get a text editor that can do RegEx search and replace and just do:

search:
(.*)\t(.*)\r

replace:
<company>\r\t<name>\1</name>\r\t<location>\2</location>\r</company>\r

check this out:
http://www.anybrowser.org/bbedit/grep.shtml


border