import xlwt
# Excel模板
def Excel_Template():
# Excel文件名, sheet页名, 表格标题
file_name_xls = "测试用例2.xls"
sheet_name_xls = "sheet"
value_title = [['标题1', '标题2'], ['100', '1000']]
write_excel_xls(file_name_xls, sheet_name_xls, value_title)
def write_excel_xls(path, sheet_name, value):
index = len(value) # 获取需要写入的列数
workbook = xlwt.Workbook() # 新建一个工作簿
sheet = workbook.add_sheet(sheet_name) # 新建一个工作表
for i in range(0, index):
for j in range(0, len(value[i])):
sheet.write(i, j, value[i][j]) # 像表格中写入数据(对应的行和列)
workbook.save(path) # 保存工作簿
print("xls格式表格写入数据成功!")
print(path)
if __name__ == "__main__":
# print(GetID())
Excel_Template()