from openpyxl import Workbook
提取出关键词信息
keyword_data = load_workbook('data.xlsx').get_sheet_by_name('detail') # 打开原有Excelname = keyword_data.cell(row=1, column=5).value # 提取单元格内容
创建Excel_Sheet
wb = Workbook() # 新建Excelwb.title = "test.xlsx" # 设置Excel名称ws = wb.active # 新建Sheetws.title = "result" # 设置Sheet名称
绘制表格
ws.merge_cells(start_row=1, end_row=1, start_column=2, end_column=4) # 合并单元格ws.cell(row=3, column=1).value = "name" # 给单元格赋值for r in range(3, 4):for c in range(2, 5):ws.cell(row=r, column=c).value = pre_total_water[r-3, c-2] # 通过循环给单元格赋值wb.save('test.xlsx')