使用openpyxl保存.xlsx文件后被Excel 2007提示损坏的问题求助
问题:openpyxl保存含图表的Excel文件后,Excel 2007提示文件损坏
在Windows 10系统中,我用Python的openpyxl库编写脚本处理.xlsx文件,即使把脚本简化到仅打开、保存、关闭三个操作,用Excel 2007打开保存后的文件仍会弹出损坏报错。
错误日志显示:/xl/comments/comment1.xml和comment2.xml文件第1行第203列存在加载错误。
我做了以下测试:
- 对无图表的空白.xlsx文件执行相同操作,无异常
- Excel自动修复该损坏文件后,重新打开不再报错
- 已定位到原文件中两个引发问题的图表工作表
现在需要:
- 解决openpyxl处理含图表工作表时导致文件损坏的问题
- 了解如何上传测试文件以便排查
用到的Python代码
from openpyxl import load_workbook import tkinter as tk from tkinter import messagebox from tkinter import simpledialog from tkcalendar import DateEntry import datetime import time from datetime import date from datetime import datetime from openpyxl.styles import Font file_path = "error test.xlsx" workbook = load_workbook(filename=file_path) worksheet = workbook.worksheets[0] # Save the file workbook.save(file_path) # Finally, close the Excel file # via the close() method. workbook.close()
内容的提问来源于stack exchange,提问作者Lakeside Park
相关产品推荐
相关产品推荐

