项目场景:
with pd.ExcelWriter('aaa.xlsx', mode='a') as writer:
data.to_excel(writer, sheet_name=developerName + '.' + fileDirectory, index=False, header=False, startrow=1, startcol=1)
问题描述
Traceback (most recent call last):
File "D:\Java\python\com\cll\coverageHtml\Coverage.py", line 356, in buttonFuntion
with pd.ExcelWriter(excelFileDirectoryArr[excelInt], mode='a') as writer:
File "C:\Users\30270\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\excel\_xlsxwriter.py", line 203, in __init__
raise ValueError("Append mode is not supported with xlsxwriter!")
ValueError: Append mode is not supported with xlsxwriter!
原因分析:
解决方案:
需要将引擎指定为“openpyxl”, 追加engine="openpyxl"
with pd.ExcelWriter(excelFileDirectoryArr[excelInt], engine="openpyxl", mode='a') as writer:
data.to_excel(writer, sheet_name=developerName + '.' + fileDirectory, index=False, header=False, startrow=1, startcol=1)
在尝试使用pandas的ExcelWriter以追加模式(a)写入Excel文件时,遇到ValueError,提示xlsxwriter不支持追加模式。解决方案是将ExcelWriter的引擎改为openpyxl,这样就可以在已有文件上追加数据。
1万+

被折叠的 条评论
为什么被折叠?



