How to convert Excel SpreadsheetML to .xlsx using python

725 views Asked by At

I'm new to python, so i have this XML file which i can open pretty easily using Excel, this is XML file

andi want to convert it to .xlsx or any compatible format to be able to use openpyxl module to it so that i can read it easily, is there any way to do this on python? Any advice would be appreciated thankyou.

1

There are 1 answers

0
Kostas Nitaf On

I had the same problem. This answer helped me Attempting to Parse an XLS (XML) File Using Python

You may save your Excel styled XML as xlsx with Workbook.SaveAs method using win32com (only for Windows users) and read in with pandas.read_excel

import win32com.client
import pandas as pd

original_file = "Your_downloaded_file.xml"
output = "Your_converted_file.xlsx"

xlApp = win32com.client.Dispatch("Excel.Application")
xlWbk = xlApp.Workbooks.Open(original_file)
xlWbk.SaveAs(output, 51)
xlWbk.Close(True)
xlApp.Quit()

output_df = pd.read_excel(output)
print(output_df.columns.ravel())