Computer >> Computer tutorials >  >> Software >> Office

How to Convert XML to Columns In Excel (4 Suitable Ways)

In this tutorial, I am going to show you 4 suitable ways to convert XML to columns in excel. You can use these methods even in large datasets to find out the data cells from XML data values. Throughout this tutorial, you will also learn some important excel tools and techniques which will be very useful in any excel related task.

You can download the practice workbook from here.

4 Suitable Ways to Convert XML to Columns in Excel

We have taken a relatively concise XML dataset to explain the steps clearly. The dataset has approximately 7 rows and 2 columns. Initially, we are keeping all the cells in General format. For all the datasets, we have 2 unique columns which are Site Location URL and Date. Although we may vary the number of columns later on if that is needed.

1. Using XML from Local System

In this first method, we will convert XML to columns in excel from our local system. Let us see how to do this.

Steps:

  • First, go to the Data tab and click on Get Data.
  • Next, select From File and then click on From XML.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Now, select an XML file and click Import.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Then, in the Navigator window, select the XML data name and click Load.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Consequently, this will create excel columns from the imported file.

How to Convert XML to Columns In Excel (4 Suitable Ways)

Read More: How to Extract Data from XML File to Excel (2 Easy Ways)

2. Fetching XML from Web

We can also fetch XML data from the web using URL and convert it to columns in excel. Follow the steps below for this.

Steps:

  • To begin with, go to the Data tab and click From Web.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Here, paste the URL of the XML file and click OK.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Now, select the appropriate file path and click Connect.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • As before, select the XML data name and click Load.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Immediately, you should get the respective excel columns.

How to Convert XML to Columns In Excel (4 Suitable Ways)

Read More: How to Convert XML to XLSX Without Opening File

3. Applying FILTERXML Function

The FILTERXML function in excel gives us the ability to convert cell data into columns from XML data. Below are the detailed steps.

Steps:

  • To start with, copy the XML file data and paste it into cell B4 of an excel sheet.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Then, go to a new sheet and insert this formula in cell B5:
=FILTERXML(FILTERXML!B5,"//PLANT/COMMON")

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Finally, press Enter and this should generate the excel columns from the XML file as we wanted.

How to Convert XML to Columns In Excel (4 Suitable Ways)

4. Utilizing VBA Code

If you are familiar with VBA in excel, then you can easily convert XML to columns using just a few lines of code.

Steps:

  • For this method, go to the Developer tab and select Visual Basic.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Now, select Insert in the VBA window and click on Module.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Next, type in the formula below in the new window:
Sub XML_to_Column()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim wBook As Workbook
With Workbooks.OpenXML("C:\Users\ASUS\Downloads\sitemap_index.xml" _
, , xlXmlLoadImportToList)
.SaveAs ("C:\Users\ASUS\Downloads\Salary_Sheet.xlsx")
.Close
End With
End Sub

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Then, open the macro from the Developer tab by clicking on Macros.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Now, in the Macro window, select the XML_to_Column macro and click Run.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • As a result, the VBA code will create the columns inside cells B4 to C10.

How to Convert XML to Columns In Excel (4 Suitable Ways)

Read More: How to Convert Large XML to Excel (2 Effective Ways)

How to Convert XML to CSV in Excel

If you want to convert an XML file to CSV, then there is a very easy option to do this. Let us see that.

Steps:

  • Firstly, click on the File option in the top-left corner of the window.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • After that, select Export and then click on Change File Type.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Here, select CSV under Other File Types and click Save As.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Next, give a name to the file and click Save.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • As a result, this will generate the CSV file which you can open with Notepad or any other text editor.

How to Convert XML to Columns In Excel (4 Suitable Ways)

Read More: How to Open XML File in Excel (2 Easy Ways)

How to Convert XML to Excel Table

We can also convert an XML file directly into an excel table. The process is somewhat similar to what we have seen already. So, let us follow the steps below.

Steps:

  • As previously, navigate to the Data tab and select Get Data.
  • Then, click From XML under From File.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Next, select the XML file and click Import.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Now, select the XML data name and click Load To.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Then, in the Import Data window, select Table and click OK.

How to Convert XML to Columns In Excel (4 Suitable Ways)

  • Finally, this will convert the XML file into an excel table.

How to Convert XML to Columns In Excel (4 Suitable Ways)

Read More: How to Convert Large XML to Excel (2 Effective Ways)

Conclusion

I hope that you were able to apply the methods that I showed in this tutorial on how to convert XML to columns in excel. As you can see, there are quite a few ways to achieve this. So wisely choose the method that suits your situation best. If you get stuck in any of the steps, I recommend going through them a few times to clear up any confusion. Lastly, to learn more excel techniques, follow our ExcelDemy website. If you have any queries, please let me know in the comments.

Related Articles

  • How to Add Custom Ribbon Using XML in Excel
  • How to Open XML File in Excel for Income Tax (2 Easy Ways)