从 openpyxl 中的 zipfolder 打开 Excel 文件

Open Excel file from zipfolder in openpyxl

我正在尝试以下代码。

from zipfile import ZipFile
from openpyxl import load_workbook
from io import BytesIO

zip_path = r"path/to/zipfile.zip"
with ZipFile(zip_path) as myzip:
    with myzip.open(myzip.namelist()[0]) as myfile:
        wb = load_workbook(filename=BytesIO(myfile.read()))
        data_sheet = wb.worksheets[1]
        for row in data_sheet.iter_rows(min_row=3, min_col=3):
            print(row[0].value)

显示

ValueError: stat: path too long for Windows

这可能吗?

我正在尝试来自 Using openpyxl to read file from memory

的逻辑

对于 xlrd,下面的代码工作正常。

with ZipFile(zip_path) as myzip:
        with myzip.open(myzip.namelist()[0]) as myfile:
            book = xlrd.open_workbook(file_contents=(myfile.read()))
    sh = book.sheet_by_index(0)
    #your code here