1.导入包
from xlutils.copy import copy
import xlrd
2.打开excel
# 打开文件
xlrd.open_workbook(excel_path)
# 获取操作表
table = data.sheets()[0]
3.获取表格数据
# 获取行数
rows = table.nrows
# 获取指定单元格数据
cell = table.cell(row, col).value
# 获取一行数据
col = table.row_values(i)
4.在已有表格中进行写操作
# 复制已有表格
write_excle = copy(data)
# 在指定单元格写入内容
write_excle.get_sheet(0).write(row, col, value)
#保存文件
write_excle.save(excel_path)
注意:复制后的表格为xls格式,使用xlsx无法打开,需修改文件类型