You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用openpyxl写入xlsx文件失败,遭遇IndexError与BadZipFile错误

问题

我尝试用openpyxl把批量实验的文本信息写入Excel文件做数据分析,常碰到两种错误:

  1. IndexError: At least one sheet must be visible
  2. 尝试手动命名工作表解决第一个错误时,又出现BadZipFile: File is not a zip file

用到的Python代码

with pd.ExcelWriter(exp_xlsx, engine = 'openpyxl') as writer: 
    if glob.glob(exp_xlsx) != []: # add "or ((overwrite != True) and (run_num == run_min)) 
        writer.book = load_workbook(exp_xlsx)  # open an existing workbook
        writer.sheets = dict((ws.title, ws) for ws in writer.book.worksheets) # copy existing sheets
        reader = pd.read_excel(exp_xlsx)# read existing file

读取的文件结构

文件包含一个名为Sheet1的工作表,表头有sample_id、parameter1、parameter2、parameter3、parameter4、parameter5、parameter6、parameter7共8列,下方对应有数据行。

内容的提问来源于stack exchange,提问作者William A Anderson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 01:55:02