这个python openpyxl“ValueError"是什么意思?吝啬的? [英] What does this python openpyxl "ValueError" mean?

查看:208
本文介绍了这个python openpyxl“ValueError"是什么意思?吝啬的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法确定我收到此错误的原因.有人知道这种错误的原因是什么吗?

I cannot identify why I am getting this error. Does anybody know what is the reason for such error?

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 我只是将值复制到其中,而不是代码工作的整个工作表.

What is interesting is that with other excel file I do not get this error... Therefore I am curious what is the problem with a completely "new excel", with one sheet and one table that I am trying to read... and other excel into which I just copied the values, not the whole sheet the code works.

推荐答案

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

I'm going to give this an educated guess:

  • 最后一行(ValueError: Value must be one of {0, 1, 2, [...])告诉我们Excel文件中的some值包含不受支持的值.
  • 沿着回溯我们看到:[...] openpyxl\styles\alignment.py", line 59, in __init__ 这让我相信这是something 与文本对齐有关.
  • 考虑到这一点,最后一行变得更有趣:Value must be one of {0, 1, [...] 179, 180}:可能的值范围从0 到 180.那么这可能与文本旋转有关吗?
  • The last line (ValueError: Value must be one of {0, 1, 2, [...]) tells us that some value in the Excel file contains an unsupported value.
  • Going up the traceback we see this: [...] openpyxl\styles\alignment.py", line 59, in __init__ which leads me to believe that this is something to do with text alignment.
  • With this in mind, the last-line becomes a bit more interesting: Value must be one of {0, 1, [...] 179, 180}: The possible values range from 0 to 180. So could this possibly be related to text-rotation?

会不会是可以运行的 Excel 文件没有任何旋转文本,而失败的文件?如果是,您可以尝试删除旋转并重试吗?

Could it be that the Excel file which works does not have any rotated text, but the file which fails does? If yes, can you try to remove the rotation and try again?

这篇关于这个python openpyxl“ValueError"是什么意思?吝啬的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆