gpt4 book ai didi

打开pyxl+load_workbook+AttributeError : 'NoneType' object has no attribute 'date1904'

转载 作者:行者123 更新时间:2023-12-02 20:59:39 30 4
gpt4 key购买 nike

当我使用 openpyxl 加载 Excel 文件 (.xlsx) 时,显示此错误(最后一个链接是示例 Excel 文件):

from openpyxl import * wb = load_workbook("D:/develop/workspace/exman/test sample/510001653.xlsx")

Traceback (most recent call last):

File "", line 1, in

File "C:\Python34\lib\site-packages\openpyxl-2.5.0-py3.4.egg\openpyxl\reader\ xcel.py", line 161, in load_workbook

parser.parse()

File "C:\Python34\lib\site-packages\openpyxl-2.5.0-py3.4.egg\openpyxl\packagi g\workbook.py", line 42, in parse

if package.properties.date1904:

AttributeError: 'NoneType' object has no attribute 'date1904'

sample excel file download

最佳答案

我调试 python 文件,发现 workbookPr = None,导致 package.properties 为 None( properties = Alias(workbookPr)。所以我像下面这样更改 workbookParser.parser() 的代码,错误解决了.

class WorkbookParser:

def __init__(self, archive):
self.archive = archive
self.wb = Workbook()
self.sheets = []
self.rels = get_dependents(self.archive, ARC_WORKBOOK_RELS)


def parse(self):
src = self.archive.read(ARC_WORKBOOK)
node = fromstring(src)
package = WorkbookPackage.from_tree(node)

if package.properties is not None: #add this line
if package.properties.date1904:
wb.excel_base_date = CALENDAR_MAC_1904
self.wb.code_name = package.properties.codeName
self.wb.active = package.active

..........

关于打开pyxl+load_workbook+AttributeError : 'NoneType' object has no attribute 'date1904' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38967587/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com