python之自定义表头、列表内容导出excel文件例子

函数三个参数

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)

结果示例 

相关推荐

  1. ThinkPHP6 定义Excel导出

    2024-03-20 19:52:01       36 阅读
  2. 定义注解实现Excel 导出

    2024-03-20 19:52:01       7 阅读
  3. 报表定义导出文件名

    2024-03-20 19:52:01       45 阅读
  4. Apache Calcite - 定义数据源适配访问内存列表

    2024-03-20 19:52:01       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-20 19:52:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-20 19:52:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-20 19:52:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-20 19:52:01       20 阅读

热门阅读

  1. 了解比特币分叉:演变与分歧

    2024-03-20 19:52:01       19 阅读
  2. Docker 命令大全

    2024-03-20 19:52:01       19 阅读
  3. LeetCode204. Count Primes

    2024-03-20 19:52:01       22 阅读
  4. 描述一下使用过的任何安全测试工具及其功能

    2024-03-20 19:52:01       24 阅读
  5. 分布式事务的实现方式

    2024-03-20 19:52:01       23 阅读
  6. C++ 函数模板

    2024-03-20 19:52:01       20 阅读
  7. 机器学习模型—K means

    2024-03-20 19:52:01       20 阅读
  8. 实验11-1-9 藏尾诗(PTA)

    2024-03-20 19:52:01       21 阅读