[英]Unable to load workbook (<TypeError: expected <class 'openpyxl.chart.axis.NumericAxis'>)
import openpyxl
wb = openpyxl.load_workbook('test.xlsm', data_only=True)
sheets = wb.sheetnames
x = wb[sheets[0]]
But I got this error:但我得到了这个错误:
TypeError: expected <class 'openpyxl.chart.axis.NumericAxis'>
What I understood is that openpyxl
cannot open sheet with graph, not anymore at least.我的理解是,
openpyxl
不能用图表打开工作表,至少现在不能。
But I only need on sheet, and there is no graph inside.但我只需要在纸上,里面没有图表。
Is there a way to directly tell openpyxl
to open only one sheet and not waiting after wb = openpyxl.load_workbook('test.xlsx', data_only=True)
有没有办法直接告诉
openpyxl
只打开一张纸,而不是在wb = openpyxl.load_workbook('test.xlsx', data_only=True)
之后等待
Or if you have other ideas?或者如果你有其他想法?
Apparently it's based on the source code so I'm kind of stuck with that.显然它是基于源代码的,所以我有点坚持。 Source:
资源:
https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1360 https://foss.heptapod.net/openpyxl/openpyxl/-/issues/1360
如果该包有一个错误导致您无法在完整文件上使用它,并且您找不到另一个包来代替,您可以尝试通过查找另一个允许您打开 Excel 工作簿的包来解决该问题,然后从中提取一张工作表到一个临时工作簿文件中,然后使用该临时文件进行 openpyxl 调用。
As Charlie Clark said, read-only mode helps (solved the issue for me when opening a XLSM file).正如查理克拉克所说,只读模式有帮助(在打开 XLSM 文件时为我解决了这个问题)。 This should work just fine, and possibly faster:
这应该可以正常工作,并且可能更快:
import openpyxl
wb = openpyxl.load_workbook('test.xlsm', data_only=True, read_only=True)
sheets = wb.sheetnames
x = wb[sheets[0]]
Be sure to read the openpyxl documentation on Optimised Modes because there are some caveats in read-only / write-only modes.请务必阅读有关优化模式的 openpyxl 文档,因为在只读/只写模式中有一些警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.