import openpyxl,os #这是调用的编写excel的库
from openpyxl import load_workbook
path = '/home/zhouweiwei/xml_static/'
if not os.path.exists(path): #在启动程序的时候就生成的excel
os.makedirs(path)
wb = openpyxl.Workbook()
sheet = wb.active
sheet.title = '1122统计表'
wb.save(path + 'static.xlsx')
#将原有的excel打开,在这里将文件打开,并将list写进excel中
def write_to_excel(times_list, names_list): # 对外的路径,事件的列表,行,列
excel = load_workbook(r'/home/zhouweiwei/xml_static/static.xlsx')
table = excel.get_sheet_by_name('1122统计表')
rows = table.max_row
if rows ==1:
for i in range(len(times_list)):
table.cell(row=1,column=i+1,value=names_list[i])
table.cell(row=2,column=i+1,value=times_list[i])
else:
for i in range(len(times_list)):
table.cell(row=rows+1,column=i+1, value=times_list[i])
excel.save(path + 'static.xlsx')