python 将xmind用例转换为excel用例
# -*- coding: utf-8 -*- from xmindparser import xmind_to_dict import xlwt # 记录列数,全局变量,还原方便 columnIndex = 0 # 记录行数 rowIndex = 1 # 每个完整用例子主题的个数 caseCount = 0 def get_xmind_zen_dict(ws, main_topic): """ ws:工作表 main_topic:主功能点 """ # 获取功能模块个数 feature_topic_count = len(case_topics_count) global rowIndex global columnIndex global caseCount title_list = ['用例目录', '用例名称', '前提条件', '操作步骤', '期望结果'] # 用例标题写入excel首行 for j in range(0, len(title_list)): ws.write(0, j, title_list[j]) j += 1 # 比对功能点,并写入固定列 for index in range(0, feature_topic_count): # 当前层级主题的标题 topic_title = case_topics_count[index]['title'] # 将已经提取出来的外层主题进行对比,设置为最外层的用例名 if topic_title in main_topic: columnIndex = 1 # 设置功能点key到固定列 # 将功能点写入固定列 ws.write(rowIndex, columnIndex, topic_title) if 'topics' in case_topics_count[index].keys(): # 开始读取功能用例,并记录用例个数 caseCount += 1 topic_topics = case_topics_count[index]['topics'] # 获取用例步骤 # 写前提条件 if 'topics' in topic_topics[0]: qianti_topics = topic_topics[0]['topics'] qianti_topics_j = [] for title in qianti_topics: qianti_topics = title['title'].encode('utf-8') # unicode编码转str qianti_topics_j.append(qianti_topics) # 追加内容 qianti = "\n".join([str(e) for e in qianti_topics_j]) # 拼接并换行 ws.write(rowIndex, columnIndex + 1, qianti) # 写步骤 step_topics = topic_topics[1]['topics'] step_topics_j = [] for title in step_topics: step_topics = title['title'].encode('utf-8') step_topics_j.append(step_topics) step = "\n".join([str(e) for e in step_topics_j]) # 拼接多个步骤并换行 ws.write(rowIndex, columnIndex + 2, step) # 写预期结果 yuqi_topics = topic_topics[2]['topics'] yuqi_topics_j = [] for title in yuqi_topics: yuqi_topics = title['title'].encode('utf-8') yuqi_topics_j.append(yuqi_topics) yuqi = "\n".join([str(e) for e in yuqi_topics_j]) ws.write(rowIndex, columnIndex + 3, yuqi) rowIndex += 1 # 写系统版本,功能模块 system_version = case_title + '-' + case_title_s for i in range(0, caseCount): ws.write(i+1, 0, system_version) print('用例总数%s:' % caseCount) if __name__ == '__main__': # 用例地址 file_path = 'Iot Platform V2.1系统管理优化用例.xmind' save_file = 'export.xlsx' # 首层画布 xmind_origin = xmind_to_dict(file_path) # 用例标题 case_title = xmind_origin[0]['topic']['title'] case_title_s = xmind_origin[0]['topic']['topics'][0]['title'] # 获取功能模块 # 主用例 case_topics = xmind_origin[0]['topic']['topics'] # 取出单个模块的功能用例 case_topics_count = case_topics[0]['topics'] # 需要把功能点title记录下来,以便进行匹配 main_topic = [] for topic in case_topics_count: main_topic.append(topic['title']) # 使用xlwt模块 wb = xlwt.Workbook(encoding='utf-8') ws = wb.add_sheet('Test', cell_overwrite_ok=True) # 用例集遍历 get_xmind_zen_dict(ws, main_topic) # 保存Excel文档 wb.save('export.xls')
本文来自博客园,作者:ReluStarry,转载请注明原文链接:https://www.cnblogs.com/relustarry/p/15526022.html
标签:
xmind转excel
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统