简体   繁体   English

openpyxl不将数据帧写入Excel工作表

[英]openpyxl not writing dataframe to excel sheet

I have some code to write a pandas dataframe to an excel sheet and for some reason it just doesn't do anything. 我有一些代码将pandas数据框写入Excel工作表,由于某种原因,它什么也没做。 I have used the same method previously with success. 我以前成功使用过相同的方法。

book = load_workbook(os.path.commonpath(output)) #user is prompted for output file earlier in program
writer = pd.ExcelWriter(os.path.commonpath(output), engine = 'openpyxl')
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)

df.to_excel(writer, sheet_name = 'Check', startrow = writer.sheets['Check'].max_row, index = False) # this should write the df out starting at the first row that doesn't contain any data in the excel sheet. 

The program runs fine, just no output to the excel sheet when I open it. 程序运行正常,打开时仅没有输出到excel工作表。 Any ideas? 有任何想法吗?

我相信您在代码的末尾需要一个writer.save()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM