简体   繁体   English

如何使用 python 将 Excel SpreadsheetML 转换为.xlsx

[英]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我是 python 的新手,所以我有这个 XML 文件,我可以使用 Excel 轻松打开它, 这是 XML 文件

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?我想将它转换为 .xlsx 或任何兼容的格式,以便能够对其使用 openpyxl 模块,以便我可以轻松阅读它,有没有办法在 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这个答案帮助我尝试使用 Python 解析 XLS (XML) 文件

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您可以使用 win32com 使用 Workbook.SaveAs 方法将样式为 XML 的 Excel 保存为 xlsx(仅适用于 Windows 用户)并使用 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())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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