python写入excel表格_Python如何使用ExcelWriter写入现有工作表

在尝试使用ExcelWriter向包含多个工作表的工作簿中写入/添加信息时遇到问题。第一次调用函数创建包含一些数据的工作簿,第二次调用时希望在所有工作表的不同位置添加信息。解决方案是使用openpyxl的load_workbook加载现有工作簿,然后通过ExcelWriter保存更改。
摘要由CSDN通过智能技术生成

1586010002-jmsa.png

I am trying to use ExcelWriter to write/add some information into a workbook that contains multiple sheets.

First time when I use the function, I am creating the workbook with some data. In the second call, I would like to add some information into the workbook in different locations into all sheets.

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()

In the main code I call this function twice with different col to print out my data in d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值