修改xmind2testcase支持导出xlsx文档

  • Post author:
  • Post category:其他




背景

无意之间发现xmind2testcase这个工具可以将xmind的用例进行转换并批量导入到禅道中,很高兴的下载了试用一下,导出的csv文件手动保存一下为xlsx格式(只能导出csv格式的,而公司用的禅道版本又只支持xlsx格式的导入),导入的内容识别正确,就是每次都要手动转换一下,比较麻烦,所以添加了一部分代码,让这个工具支持将xmind导出成xlsx格式,

此工具的使用方法,访问原作者的git地址:

xmind2testcase



操作步骤

  • 获取xmind2testcase的源码
  • 在zentao.py文件中添加函数:xmind_to_zentao_xlsx_file_by_pandas,如下:
import pandas as pd    #使用pandas包来写入excel的,需要引入
def xmind_to_zentao_xlsx_file_by_pandas(xmind_file): #xmind导出禅道用例模板的xlsx格式
    """Convert XMind file to a zentao xlsx file"""
    xmind_file = get_absolute_path(xmind_file)
    logging.info('Start converting XMind file(%s) to zentao file...', xmind_file)
    testcases = get_xmind_testcase_list(xmind_file)

    fileheader = ["所属模块", "相关需求", "用例标题", "前置条件", "步骤", "预期", "关键词", "优先级", "用例类型", "适用阶段"]  # zd:添加“相关需求”字段
    zentao_testcase_rows = []
    for testcase in testcases:
        row = gen_a_testcase_row(testcase)
        zentao_testcase_rows.append(row)

    zentao_file = xmind_file[:-6] + '.xlsx'
    df = pd.DataFrame(data=zentao_testcase_rows, columns=fileheader) #构造数据
    df.to_excel(zentao_file, index=False)  #写入文件,设置不需要索引
    logging.info('Convert XMind file(%s) to a zentao csv file(%s) successfully!', xmind_file, zentao_file)
    return zentao_file
  • 在application.py中添加路由
@app.route('/<filename>/to/zentao_xlsx')
def download_zentao_xlsx_file(filename):
    full_path = join(app.config['UPLOAD_FOLDER'], filename)

    if not exists(full_path):
        abort(404)

    zentao_xlsx_file = xmind_to_zentao_xlsx_file_by_pandas(full_path)
    filename = os.path.basename(zentao_xlsx_file) if zentao_xlsx_file else abort(404)

    return send_from_directory(app.config['UPLOAD_FOLDER'], filename, as_attachment=True)
  • 在index.html添加xlsx的访问路径
<a href="{{ url_for('download_zentao_xlsx_file',filename=record[1]) }}">xlsx</a> |
  • 在ipreview.html添加xlsx的访问路径
/ <a href="{{ url_for('download_zentao_xlsx_file',filename= name) }}">Get Zentao xlsx</a>
  • 运行application.py,即可看到此项目以运行,访问后则可以看到添加的xlsx导出链接

    效果图

    效果图



版权声明:本文为z917185537原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。