Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Add A Field To An Xml Map

Tags:

xml

excel

vba

I've a XML map on an Excel 2010 worksheet, that I refresh from the contents of an XML file on a regular basis. I recently added a new field to the XML data and wish this to show up on my XML map.

I simply want to be able to add the new field however it appears although ill have to import the whole structure again, I dont want to do this as it will require redeveloping alot of custom formating.

Any help appreciated.

like image 397
TSUK Avatar asked Nov 18 '11 15:11

TSUK


People also ask

What is custom XML data in Excel?

Excel has a defined XML schema that defines the contents of an Excel workbook, including XML tags that store all workbook information, such as data and properties, and define the overall structure of the workbook. Custom applications can use this Excel macro-enabled Office XML Format File.

How do I map an XML schema?

In the New XML Wizard, select the Customization File Type—the type of file you want to use to create your XML layout, either DTD or XML schema. Type the name of the DTD or XML schema, type the URL, or browse to the location of the DTD or XML schema, and click Next. Select the root element.


3 Answers

Unfortunately there is no easy "refresh" method for schema in the XML object model in Excel at the moment. The XML Toolbox for Excel 2003 used to be able to do this, but I am not sure if this still runs in Excel 2010 (worth a try). Alternative to this is to write your own VBA code which would import your "new" schema into a new map, and then look at the existing element maps for the "old" schema and then remap these to the "new" schema, finally deleting the "old" one. Sounds a bit hairy I know, but if your schema doesn't change significantly then it could be the answer.

There is a less graceful method than this, which involves changing the schema in the workbook's underlying XML directly. If have a look inside the workbook structure under the xl folder, you will see that there is a file named xmlMaps.xml and inside this file will be a copy of your schema - you can then edit this directly (add new elements etc.) and the new fields will then show up for use in your workbook when you open it again in Excel, leaving your original cell formatting unchanged.

like image 101
i_saw_drones Avatar answered Oct 12 '22 23:10

i_saw_drones


This isn't exactly what the OP asked for, but it worked in my case, so I am adding it as a probable solution (using Office 2013)

  1. Right click in your ribbon and Enable Developer Tools

enter image description here

  1. Go to the new Developer Tools section on your ribbon and click Source

enter image description here

  1. This will open a righthand side flyout. Elements in bold are currently mapped to your columns. Note where things map to by clicking on them. In my case it was pretty straightforward with the first element mapping to column A, etc. Then right click on anything in bold and unmap it.

enter image description here

  1. Click the XML Maps button at bottom of flyout

  2. Click Add and navigate to a file or enter a URL

enter image description here

  1. Remove the old mapping if you want

  2. Highlight all your new elements and right click to assign a new mapping. Use the notes you jotted down earlier to do this. Again, my case was very straightforward since columns were merely appended to the end. If you have columns added in the middle, you would want to remap them to the end of your table.

like image 38
mrtsherman Avatar answered Oct 12 '22 23:10

mrtsherman


I extracted the xlsx as a zip and was able to make the changes manually without having to delete and add the mappings again following the instructions on this site: http://davidovitz.blogspot.com/2010/05/howto-refresh-xml-schema-in-excel.html

like image 31
Rubans Avatar answered Oct 12 '22 22:10

Rubans