单元格值上的OpenPYXL Python错误

时间:2017-03-21 10:12:41

标签: python openpyxl

我有一个包含大量行的excel文件,现在包含HZ,NZ或SZ的列出错了,我不知道如何修复它。

region    = ws.cell(row=srow, column=3)

if region.value == "HZ":
    nregion = "Houston"
elif region.value == "NZ":
    nregion = "North"
elif region.value == "SZ":
    nregion = "South"

以下消息出错:

Traceback (most recent call last):
  File "PowerExp.py", line 18, in <module>
    wb=load_workbook(filename = wbfile)
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 136, in load_workbook
    _load_workbook(wb, archive, filename, use_iterators, keep_vba)
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 171, in _load_workbook
    style_table = read_style_table(archive.read(ARC_STYLE))
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 42, in read_style_table
    font_list = parse_fonts(root, xmlns, color_index)
  File "/usr/local/lib/python2.7/dist-packages/openpyxl/reader/style.py", line 160, in parse_fonts
    font.size = font_node.find(QName(xmlns, 'sz').text).get('val')
AttributeError: 'NoneType' object has no attribute 'get'

我无法更改值并保存工作簿,因为它会自动从电子邮件服务器检索并加载到MySQL中。

0 个答案:

没有答案