函数三个参数
outputfile:导出excel文件的位置,没有的话在该位置建该文件
title:表头
args:列的内容,每列是一个列表
import xlsxwriter
def writeExcel(outputfile,title,*args):
wb = xlsxwriter.Workbook(outputfile)
# 创建sheet
sheet = wb.add_worksheet("Sheet")
# 写入
tag = 0
if title is not None and title != '':
for index, item in enumerate(title):
# print(index, item)
sheet.write(0, index, item) # 写入单元格数据
tag = 1
size = len(args)
# print(size)
# print(len(args[0]))
for j in range(len(args[0])): # 行
for i in range(size): # 列
# print(j,i,'['+str(i)+']'+'['+str(j)+']')
sheet.write(j+tag, i, str(args[i][j])) # 写入单元格数据
wb.close()
if __name__ == '__main__':
case_title = ['url', 'body', 'params', 'audio']
url = ['http://xxx']*len(case_title)
body = ["{'nlpmodel': 'was328'}"]*len(case_title)
params = ["{'neednlp': 'yes', 'needcontent': 'yes', 'ttssplit': 'yes'}"]*len(case_title)
audio = ['硅胶喷头.wav', '电镀涂层.wav', '陶瓷阀芯.wav', '多动出水.wav', '带置物架的.wav', '数显.wav', '升降杠.wav', '增压花洒.wav']
outputfile = 'D:\\wo\\Edge\\data.xlsx'
writeExcel(outputfile,case_title, url, params, body, audio, expected_result)
结果示例
标签:case,outputfile,自定义,title,python,args,表头,len,wav From: https://blog.csdn.net/daxiashangxian/article/details/136718628