openpyxl的一个坑

这几天一直尝试用Python来做一些Excel的自动化,xlrd,openpyxl,xlwings都尝试了,其中openpyxl有一个很奇葩的问题,即我发现无法使用load_wrokbook打开excel, xlrd和xlwings都可以。系统的提示是:

Traceback (most recent call last):
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\base.py", line 55, in _convert
    value = expected_type(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/asus/.PyCharmCE2019.3/config/scratches/test2.py", line 7, in 
    wb = load_workbook(r'E:\Documnet\工作\惠尔康\07_数据分析\临时文件\惠尔康销售情况日报表.xlsm')
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\reader\excel.py", line 317, in load_workbook
    reader.read()
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\reader\excel.py", line 279, in read
    self.read_worksheets()
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\reader\excel.py", line 254, in read_worksheets
    charts, images = find_images(self.archive, rel.target)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\reader\drawings.py", line 39, in find_images
    cs = get_rel(archive, deps, rel.id, ChartSpace)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\packaging\relationship.py", line 168, in get_rel
    obj = cls.from_tree(tree)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\chart\plotarea.py", line 140, in from_tree
    self = super(PlotArea, cls).from_tree(node)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree
    obj = desc.expected_type.from_tree(el)
  [Previous line repeated 1 more times]
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree
    return cls(**attrib)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\drawing\geometry.py", line 312, in __init__
    self.w = w
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\base.py", line 67, in __set__
    value = _convert(self.expected_type, value)
  File "C:\Users\asus\AppData\Local\Programs\Python\Python37-32\lib\site-packages\openpyxl\descriptors\base.py", line 57, in _convert
    raise TypeError('expected ' + str(expected_type))
TypeError: expected 

实在是百思不得其解,上网搜了很久也没有解决方案,最后只好从sheet1开始,一个个删除过去进行试错,最后发现居然是其中两个sheet里面有图表导致的问题,把图表删除后就能正常用了。

你可能感兴趣的:(Python)