python操作excel----新增数据

目的:想要为某个表新增数据,但是xlrd只能读

方法:

概要:通过xlrd读取表格,然后通过xlutils复制,而后保存地址为源文件,即完成新增。

代码:

import xlrd
from xlutils.copy import copy


# 读取源sql表
data_table = xlrd.open_workbook('files\last_result.xls', formatting_info=True)
# 复制源表
new_table = copy(data_table)
# 获取所有sheet
add_sheet = new_table.get_sheet(sheet_name)
# 保存为原地址,即完成修改
new_table.save('files\last_result.xls')

 

猜你喜欢

转载自blog.csdn.net/weixin_42662126/article/details/82191226