![](/img/trans.png)
[英]Python, KeyError: "There is no item named '{filename}' in the archive
[英]Getting 'KeyError: "There is no item named 'xl/sharedStrings.xml' in the archive"' when trying to open Excel
我正在尝试使用 Python 脚本将数据导入 PowerBi,以便我可以安排它定期刷新数据。 我面临着从 excel 文件获取数据并在导入时收到错误“KeyError:“档案中没有名为“xl/sharedStrings.xml”的项目””的挑战。
当我查看 xl 文件夹中 xlsx 文件的存档时,没有文件 sharedString.xml。 因为excel中没有字符串。 该文件在 excel 中正确打开,没有任何问题,但在 python 中没有。
import openpyxl
import pandas
import xlrd
import os
globaltrackerdf = pandas.read_excel (r'C:\Users\Documents\Trackers\Tracker-Global Tracker_V2-2022-06-13.xlsx',sheet_name="Sheet1",engine="openpyxl")
对我有用的解决方案:使用 excel 重新保存文件。 我的文件在 Excel 中也可以正常打开,但在压缩文件并查看内部时没有sharedStrings.xml
。 似乎存在一个错误,即保存 xlsx 可能不会生成sharedStrings.xml
文件。 我发现了关于为什么会发生这种情况的各种想法,但由于我无法访问客户的 Excel,因此不确定是什么原因造成的。
有关什么是 XLSX 文件的额外上下文,我发现这很有帮助: https ://www.adimian.com/blog/fast-xlsx-parsing-with-python/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.