编写以下代码后,我收到以下错误。在理解为什么设计用于EXCEL的openpyxl无法打开基本excel文件时,将不胜感激。预先感谢您的帮助。
import openpyxl
from openpyxl import workbook
from openpyxl import load_workbook
wb = load_workbook(file_name, read_only= True)
ValueError Traceback (most recent call last)
<ipython-input-7-9ebd7e3bdd2c> in <module>()
4
5
----> 6 wb = load_workbook(file_name, read_only= True)
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\reader\excel.py in load_workbook(filename, read_only, keep_vba, data_only, guess_types, keep_links)
199 wb.loaded_theme = archive.read(ARC_THEME)
200
--> 201 apply_stylesheet(archive, wb) # bind styles to workbook
202
203 # get worksheets
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\styles\stylesheet.py in apply_stylesheet(archive, wb)
171 return wb
172 node = fromstring(src)
--> 173 stylesheet = Stylesheet.from_tree(node)
174
175 wb._cell_styles = stylesheet.cell_styles
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\styles\stylesheet.py in from_tree(cls, node)
97 for k in attrs:
98 del node.attrib[k]
---> 99 return super(Stylesheet, cls).from_tree(node)
100
101
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py in from_tree(cls, node)
70 if hasattr(desc, 'from_tree'):
71 #descriptor manages conversion
---> 72 obj = desc.from_tree(el)
73 else:
74 if hasattr(desc.expected_type, "from_tree"):
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py in from_tree(self, node)
84
85 def from_tree(self, node):
---> 86 return [self.expected_type.from_tree(el) for el in node]
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\sequence.py in <listcomp>(.0)
84
85 def from_tree(self, node):
---> 86 return [self.expected_type.from_tree(el) for el in node]
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py in from_tree(cls, node)
87 attrib[tag] = obj
88
---> 89 return cls(**attrib)
90
91
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\styles\fonts.py in __init__(self, name, sz, b, i, charset, u, strike, color, scheme, family, size, bold, italic, strikethrough, underline, vertAlign, outline, shadow, condense, extend)
85 if underline is not None:
86 u = underline
---> 87 self.u = u
88 if strikethrough is not None:
89 strike = strikethrough
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\nested.py in __set__(self, instance, value)
34
35 value = self.from_tree(value)
---> 36 super(Nested, self).__set__(instance, value)
37
38
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\base.py in __set__(self, instance, value)
143 if value == 'none':
144 value = None
--> 145 super(NoneSet, self).__set__(instance, value)
146
147
C:\Users\Gaston\Anaconda3\lib\site-packages\openpyxl\descriptors\base.py in __set__(self, instance, value)
128 def __set__(self, instance, value):
129 if value not in self.values:
--> 130 raise ValueError(self.__doc__)
131 super(Set, self).__set__(instance, value)
132
ValueError: Value must be one of {'single', 'double', 'singleAccounting', 'doubleAccounting'}
我尝试取出read_only
部分等。错误与Excel样式有关。我使用的是Excel 2016,文件类型是xlxs。