python - openpyxl:ValueError:值必须是 {'selection'、'data'、'field'} 之一
问题描述
有一个 xlsm 文件,我需要根据工作表中启用的宏打开、编辑和提取数据。
但我无法打开文件本身。我试过了:
wb = openpyxl.load_workbook("workbook.xlsm",read_only=False,keep_vba=True)
发生错误:
Traceback (most recent call last):
File "C:/Users/Downloads/Projects/Project1/Trial4.py", line 7, in <module>
wb = openpyxl.load_workbook("workbook.xlsm",read_only=False,keep_vba=True)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\reader\excel.py", line 317, in load_workbook
reader.read()
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\reader\excel.py", line 282, in read
self.read_worksheets()
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\reader\excel.py", line 268, in read_worksheets
pivot = TableDefinition.from_tree(tree)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\descriptors\serialisable.py", line 83, in from_tree
obj = desc.from_tree(el)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\descriptors\sequence.py", line 85, in from_tree
return [self.expected_type.from_tree(el) for el in node]
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\descriptors\sequence.py", line 85, in <listcomp>
return [self.expected_type.from_tree(el) for el in node]
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
return cls(**attrib)
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\pivot\table.py", line 481, in __init__
self.scope = scope
File "C:\Users\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\openpyxl\descriptors\base.py", line 128, in __set__
raise ValueError(self.__doc__)
ValueError: Value must be one of {'selection', 'data', 'field'}
有人可以为这个问题提供解决方案。TIA
解决方案
我有同样的问题没有在互联网上找到解决方案,所以我解构了 openpyxl,我终于找到了。
似乎缺少一段代码来管理“ConditionalFormat”,因此我将其全部从源 excel 中删除。
这似乎解决了这个问题。
推荐阅读
- javascript - 响应地将div的上边缘定位在另一个div中的圆的中心点?
- python - 类型错误:'在
' 需要字符串作为左操作数,而不是 Telnetlib Python3 中的字节 - image - 来自 URL 的 Xamarin Forms 图像源被缓存?
- oracle - 更新前的 Oracle 触发器
- php - 在 Monolog (Symfony) 中使用 LogLevels
- python - Python函数不会退出或指向另一个函数
- javascript - React Native - 无法关闭控制台日志和底部选项卡导航器有一步延迟
- c# - 是否可以在大括号内使用占位符?
- python - Python 从 excel 中读取:AttributeError: 'tuple' object has no attribute 'value'
- python-3.x - 如何调用 web python 脚本以使用 GET 获取 HTTP 响应值?