用load_workbook导入Excel时的ValueError ,如何解决?

本人想用Excel表里面的数据进行决策树分类,一开始使用的数据是全数字时,不会出现问题,后来使用复杂的数据时,便出现问题。代码如下:

from openpyxl import load_workbook

wb = load_workbook(filename=r'C:/Users/Administrator/Desktop/test/data_test.xlsx') ws = wb.get_sheet_by_name("Sheet1") data = [] for row_A in range(2, 1001): arr1 = [] for row_B in range(1,13): a1 = ws.cell(row=row_A, column=row_B).value arr1.append(a1) data.append(arr1) print(wb)

出现的错误如下: ValueError Traceback (most recent call last)

<ipython-input-7-169847673234> in <module>() 1 from openpyxl import load_workbook 2 ----> 3 wb = load_workbook(filename=r'C:/Users/Administrator/Desktop/test/data_test.xlsx') 4 ws = wb.get_sheet_by_name("Sheet1") 5 data = []

D:\alex\anaconda3\lib\site-packages\openpyxl\reader\excel.py in load_workbook(filename, read_only, keep_vba, data_only, guess_types, keep_links) 256 src = archive.read(t) 257 xml = fromstring(src) --> 258 table = Table.from_tree(xml) 259 ws.add_table(table) 260

D:\alex\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py in from_tree(cls, node) 77 if hasattr(desc.expected_type, "from_tree"): 78 #complex type ---> 79 obj = desc.expected_type.from_tree(el) 80 else: 81 #primitive

D:\alex\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py in from_tree(cls, node) 90 attrib[tag] = obj 91 ---> 92 return cls(**attrib) 93 94

D:\alex\anaconda3\lib\site-packages\openpyxl\worksheet\table.py in init(self, name, showFirstColumn, showLastColumn, showRowStripes, showColumnStripes) 60 showColumnStripes=None, 61 ): ---> 62 self.name = name 63 self.showFirstColumn = showFirstColumn 64 self.showLastColumn = showLastColumn

D:\alex\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

D:\alex\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 {'PivotStyleDark24', 'TableStyleMedium15', 'PivotStyleDark4', 'PivotStyleDark27', 'TableStyleLight16', 'TableStyleLight12', 'PivotStyleMedium27', 'PivotStyleDark28', 'TableStyleMedium7', 'TableStyleDark5', 'TableStyleMedium10', 'PivotStyleDark21', 'PivotStyleMedium4', 'TableStyleDark10', 'PivotStyleLight2', 'TableStyleMedium13', 'PivotStyleDark22', 'PivotStyleMedium19', 'PivotStyleLight1', 'PivotStyleDark14', 'PivotStyleMedium18', 'PivotStyleMedium12', 'TableStyleLight11', 'TableStyleMedium11', 'PivotStyleMedium23', 'TableStyleMedium5', 'PivotStyleMedium17', 'TableStyleMedium17', 'TableStyleMedium23', 'TableStyleMedium22', 'TableStyleDark1', 'TableStyleLight5', 'TableStyleLight18', 'PivotStyleDark7', 'PivotStyleLight5', 'TableStyleMedium19', 'TableStyleMedium21', 'TableStyleDark6', 'PivotStyleLight22', 'PivotStyleDark8', 'PivotStyleLight25', 'PivotStyleLight26', 'PivotStyleLight27', 'PivotStyleLight9', 'TableStyleMedium20', 'TableStyleMedium1', 'TableStyleMedium24', 'TableStyleDark4', 'PivotStyleDark10', 'PivotStyleMedium5', 'PivotStyleDark9', 'PivotStyleDark13', 'TableStyleMedium9', 'PivotStyleLight19', 'TableStyleLight13', 'PivotStyleDark6', 'PivotStyleMedium15', 'PivotStyleMedium8', 'PivotStyleMedium26', 'TableStyleLight19', 'TableStyleLight2', 'PivotStyleMedium20', 'PivotStyleLight7', 'PivotStyleDark1', 'PivotStyleDark11', 'PivotStyleDark17', 'PivotStyleLight3', 'TableStyleDark11', 'PivotStyleMedium10', 'TableStyleLight9', 'TableStyleDark9', 'PivotStyleLight28', 'PivotStyleDark15', 'TableStyleDark7', 'PivotStyleDark2', 'TableStyleLight8', 'PivotStyleLight23', 'PivotStyleDark3', 'TableStyleMedium16', 'PivotStyleMedium3', 'PivotStyleLight14', 'PivotStyleDark5', 'TableStyleDark2', 'TableStyleDark3', 'PivotStyleLight24', 'PivotStyleMedium14', 'TableStyleLight7', 'PivotStyleLight8', 'PivotStyleLight21', 'PivotStyleMedium25', 'PivotStyleDark16', 'PivotStyleDark19', 'PivotStyleMedium6', 'TableStyleMedium8', 'PivotStyleMedium1', 'TableStyleMedium14', 'PivotStyleDark25', 'PivotStyleLight17', 'PivotStyleDark12', 'PivotStyleLight12', 'TableStyleMedium25', 'PivotStyleMedium16', 'TableStyleMedium3', 'TableStyleMedium27', 'PivotStyleMedium28', 'PivotStyleMedium11', 'TableStyleMedium18', 'PivotStyleLight4', 'PivotStyleLight6', 'TableStyleLight1', 'PivotStyleLight18', 'TableStyleMedium26', 'PivotStyleLight10', 'PivotStyleDark18', 'PivotStyleMedium21', 'TableStyleLight17', 'TableStyleMedium6', 'TableStyleLight20', 'PivotStyleDark26', 'TableStyleMedium28', 'PivotStyleLight20', 'TableStyleLight6', 'TableStyleLight10', 'PivotStyleMedium22', 'TableStyleMedium12', 'TableStyleLight14', 'TableStyleLight3', 'PivotStyleMedium24', 'PivotStyleLight15', 'TableStyleMedium2', 'TableStyleMedium4', 'PivotStyleLight11', 'PivotStyleMedium7', 'PivotStyleDark23', 'PivotStyleDark20', 'TableStyleLight21', 'PivotStyleMedium13', 'TableStyleLight15', 'TableStyleDark8', 'PivotStyleMedium2', 'PivotStyleLight13', 'TableStyleLight4', 'PivotStyleLight16', 'PivotStyleMedium9'}

0 comments