from xlrd import open_workbook
from xlutils.copy import copy
import xlrd
import xlwt
from scipy import stats
def write(list1,list2,list3,string):
# 数据记入至excel表
r_xls = open_workbook("Excel summary.xls") # 读取excel文件
rows_old = r_xls.sheets()[0].nrows # 获取已有的行数
excel = copy(r_xls) # 将xlrd的对象转化为xlwt的对象
table = excel.get_sheet(0) # 获取要操作的sheet
# print (rows_old)
# 对excel表追加一行内容
table.write_merge(1 + rows_old, 1 + rows_old, 0, 3, string)
title = ["医生", "总手术数", "rob数", "非rob数"]
# 写入"医生", "总手术数", "rob数", "非rob数"标题
for i in range(0, len(title)):
table.write(2 + rows_old, i, title[i])
for i in range(0, len(list1)):
table.write(i + 3 + rows_old, 0, list1[i])
table.write(i + 3 + rows_old, 1, str(list2[i] + list3[i]))
table.write(i + 3 + rows_old, 2, str(list2[i]))
table.write(i + 3 + rows_old, 3, str(list3[i]))
excel.save("Excel summary.xls") # 保存并覆盖文件
python数据记入至excel表
最新推荐文章于 2024-08-15 01:55:01 发布