简体   繁体   中英

How to convert Excel SpreadsheetML to .xlsx using python

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.

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM