用python实现xmind用例转换为excel/csv用例

python 复制代码
from xmindparser import xmind_to_dict
from openpyxl import Workbook

# 解析XMind文件
xmind_file = 'path/to/xmind/file.xmind'
xmind_data = xmind_to_dict(xmind_file)

# 创建Excel文件
excel_file = 'path/to/excel/file.xlsx'
wb = Workbook()
ws = wb.active

# 定义用例表格的列名
ws['A1'] = 'Title'
ws['B1'] = 'Description'
ws['C1'] = 'Priority'
ws['D1'] = 'Steps'
ws['E1'] = 'Expected Result'

# 获取用例数据
case_data = xmind_data['topics'][0]  # 假设用例数据在第一个主题下

# 将用例数据写入Excel文件
row = 2  # 从第二行开始写入数据

def process_topic(topic):
    global row
    title = topic['title']
    description = topic['topics'][0]['title']
    priority = topic['topics'][0]['topics'][0]['title']
    steps = topic['topics'][0]['topics'][0]['topics']
    for step in steps:
        step_title = step['title']
        step_description = step['topics'][0]['title']
        # 将用例数据写入Excel文件的相应单元格
        ws[f'A{row}'] = title
        ws[f'B{row}'] = description
        ws[f'C{row}'] = priority
        ws[f'D{row}'] = step_title
        ws[f'E{row}'] = step_description
        row += 1

process_topic(case_data)

# 保存Excel文件
wb.save(excel_file)

xmind转换成csv

python 复制代码
import csv
from xmindparser import xmind_to_dict

# 解析XMind文件
xmind_file = 'path/to/xmind/file.xmind'
xmind_data = xmind_to_dict(xmind_file)

# 创建CSV文件
csv_file = 'path/to/csv/file.csv'
csv_columns = ['Title', 'Description', 'Priority', 'Steps', 'Expected Result']
csv_data = []

# 获取用例数据
case_data = xmind_data['topics'][0]  # 假设用例数据在第一个主题下

def process_topic(topic):
    title = topic['title']
    description = topic['topics'][0]['title']
    priority = topic['topics'][0]['topics'][0]['title']
    steps = topic['topics'][0]['topics'][0]['topics']
    for step in steps:
        step_title = step['title']
        step_description = step['topics'][0]['title']
        # 将用例数据添加到CSV数据列表中
        csv_data.append({
            'Title': title,
            'Description': description,
            'Priority': priority,
            'Steps': step_title,
            'Expected Result': step_description
        })

process_topic(case_data)

# 将CSV数据写入CSV文件
with open(csv_file, 'w', newline='') as file:
    writer = csv.DictWriter(file, fieldnames=csv_columns)
    writer.writeheader()
    for data in csv_data:
        writer.writerow(data)
相关推荐
空堂与归19 小时前
大模型再火,也得先过 class 这一关
python
Muselit19 小时前
Python 泛型:把 list[User] 讲明白
python·fastapi
2501_9160074719 小时前
Python实现HTTPS爬虫的完整指南:使用requests、BeautifulSoup、Selenium和Scrapy
爬虫·python·ios·小程序·https·uni-app·iphone
gptAI_plus19 小时前
别把整个仓库塞给 AI:用 Python 生成安全的代码上下文清单
python·chatgpt
吃饱了得干活19 小时前
Agent 记忆系统:从短期记忆到长期记忆
python·langchain·agent
大鱼>19 小时前
DSPy:LLM程序自动编译与提示词优化
开发语言·人工智能·python·深度学习
2401_8432537019 小时前
金融智能:AI如何重构银行业未来
人工智能·python·金融
uncle_ll19 小时前
服务器选型、微调范式、训练优化与环境搭建
服务器·python·gpt·llm·nlp
久久学姐20 小时前
Python开发爬虫的常用技术架构
爬虫·python·http·框架·数据存储
circuitsosk20 小时前
大规模离线数据管道构建:样本获取、清洗、加工与合成
人工智能·python·机器学习·搜索引擎