我有一个应用程序"program.exe“,它有一个excel文件作为参数:
program.exe file.xlsx
首先需要修改"file.xlsx“。特别是,我需要使用一些计算来转储数据帧:
wb = load_workbook(filename="file.xlsx")
ws = wb.active
list2d = df.values.tolist()
for r_idx, row in enumerate(list2d, 1):
for c_idx, value in enumerate(row, 1):
ws.cell(row=r_idx+start_row, column=c_idx, value=value)
wb.save("file.xlsx")
但是,除非我手动打开并保存文件,否则我的程序不接受"file.xlsx“。我看到一些其他用户遇到了同样的问题,但显然没有得到解决?
发布于 2020-04-11 04:14:40
关于评论的扩展:
是的,程序是这样开始的:
import openpyxl as xl
wb = xl.Workbook()
ws = wb.active
[lots of code to create/format the worksheet]
最后是这样结束的:
f = '/home/chris/myDir/outFile.xlsx'
wb.save(f)
Popen(['localc', f]) # to open the file after saving, as there's no way to simply open the worksheet/book after creating with openpyxl--`Popen` exists within the `subprocess` package
需要说明的是,outFile.xlsx
是一个已经存在并且正在保存的文件。
https://stackoverflow.com/questions/61147645
复制相似问题