这个python openpyxl“ValueError”是什么意思?

问题描述 投票:0回答:2

我无法确定为什么会出现此错误。有谁知道这个错误的原因是什么?

Traceback (most recent call last):
  File "c:/Users/g401428/Documents/Visual Studio Code/jackpotCalc/calculationFGTriggerProb.py", line 49, in <module>
    wb1 = load_workbook(excel_mb_path , read_only=True, keep_vba=False, data_only=True, keep_links=False)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\reader\excel.py", line 312, in load_workbook
    reader.read()
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\reader\excel.py", line 273, in read
    apply_stylesheet(self.archive, self.wb)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\styles\stylesheet.py", line 189, in apply_stylesheet
    stylesheet = Stylesheet.from_tree(node)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\styles\stylesheet.py", line 103, in from_tree
    return super(Stylesheet, cls).from_tree(node)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py", line 88, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py", line 88, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py", line 88, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\serialisable.py", line 104, in from_tree
    return cls(**attrib)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\styles\alignment.py", line 59, in __init__
    self.textRotation = int(textRotation)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\base.py", line 145, in __set__
    super(NoneSet, self).__set__(instance, value)
  File "C:\Users\g401428\AppData\Local\Continuum\anaconda3\lib\site-packages\openpyxl\descriptors\base.py", line 130, in __set__
    raise ValueError(self.__doc__)
ValueError: Value must be one of {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180}

我使用此代码收到此错误:

excel_mb_path = "C:\\Users\\Book1.xlsx"

wb1 = load_workbook(excel_mb_path , read_only=True, keep_vba=False, data_only=True, keep_links=False)

有趣的是,对于其他 excel 文件,我没有收到此错误...因此我很好奇一个完全“新的 excel”(我正在尝试阅读的一张表和一张表)有什么问题...和其他 Excel,我只是将值复制到其中,而不是代码工作的整个工作表。

python excel python-3.x openpyxl valueerror
2个回答
3
投票

我将给出一个有根据的猜测:

  • 最后一行 (
    ValueError: Value must be one of {0, 1, 2, [...]
    ) 告诉我们 Excel 文件中的 some 值包含不受支持的值。
  • 向上追溯,我们看到这个:
    [...] openpyxl\styles\alignment.py", line 59, in __init__
    ,这让我相信这与文本对齐有关。 考虑到这一点,最后一行变得更有趣:
  • Value must be one of {0, 1, [...] 179, 180}
  • :可能的值范围从 0 到 180。那么这可能与文本旋转有关吗?
    
    
    
  • 是否可以正常工作的 Excel 文件没有任何旋转文本,而失败的文件
却有

?如果是的话,您可以尝试取消旋转并重试吗?


0
投票
或者 使用 read_only = True,


wb = load_workbook(filename,read_only = True)

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.