我正在尝试使用ExcelWriter将一些信息写入/添加到包含多个工作表的工作簿中.我第一次使用该函数时,我正在创建包含一些数据的工作簿.在第二个调用中,我想在不同位置的工作簿中将一些信息添加到所有工作表中.
def Out_Excel(file_name,C,col):
writer = pd.ExcelWriter(file_name,engine='xlsxwriter')
for tab in tabs: # tabs here is provided from a different function that I did not write here to keep it simple and clean
df = DataFrame(C) # the data is different for different sheets but I keep it simple in this case
df.to_excel(writer,sheet_name = tab, startcol = 0 + col, startrow = 0)
writer.save()
Run Code Online (Sandbox Code Playgroud)
在主代码中,我使用不同的col调用此函数两次,以在不同位置打印出我的数据.
Out_Excel('test.xlsx',C,0)
Out_Excel('test.xlsx',D,10)
Run Code Online (Sandbox Code Playgroud)
但问题是这样做输出只是函数的第二次调用,就像函数覆盖整个工作簿一样.我想我需要加载本案例中已经存在的工作簿?有帮助吗?