Wednesday 3 October 2018

Split Excel column with XML inside


Is there a way to break an Excel column containing XML into several columns like this:


BEFORE


| Apples | Pears | XML                              |
| ------ | ----- | ---------------------------------|
| 35 | 18 | 3419 |
| 86 | 55 | 1262 |
| 99 | 12 | 1823 |

AFTER


| Apples | Pears | Plums | Figs |
| ------ | ----- | ----- | ---- |
| 35 | 18 | 34 | 19 |
| 86 | 55 | 12 | 62 |
| 99 | 12 | 18 | 23 |

The original table comes from an SQL Server that stores XML in a text column. If the XML column contained comma-separated values, I'd tell Excel to do Text to Columns. Is there a similar feature for XML?



Answer



In addition to Text manipulation in Excel there are two other options.




  1. You could use VBA to parse the XML. You could either use string functions to look for tags or actually use XML parsers to walk the content (see this question on SO for more info).




  2. You can use the XML Source feature in Excel (see here for an overview). The easiest way to use this is to load in an XML file. Excel will automatically try and create an XML map for the loaded data and load it into a table. For it to really work well though you need to create a schema.




For your data I added a root element and saved this in a file:



3419
1262
1823


Loaded into Excel this creates the following table:


enter image description here


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...