用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)
相关推荐
电商API&Tina20 分钟前
比价 / 选品专用:京东 + 淘宝 核心接口实战(可直接复制运行)
大数据·数据库·人工智能·python·json·音视频
love530love32 分钟前
Windows 开源项目部署评估与决策清单(完整版)
人工智能·windows·python·开源·github
今夕资源网35 分钟前
零基础 Python 环境搭建工具 一键安装 Python 环境自动配置 升级 pip、setuptools、wheel
开发语言·python·pip·环境变量·python环境变量·python自动安装
Derrick__11 小时前
Scrapling 爬取豆瓣电影Top250
开发语言·python·网络爬虫·豆瓣·scrapling
2401_835792541 小时前
Java复习上
java·开发语言·python
Ai财富密码1 小时前
AI生成大屏可视化:数据智能驱动下的高维洞察与决策中枢
开发语言·人工智能·python·sdd
半兽先生1 小时前
01阶段:大模型语言入门
开发语言·python
l1t1 小时前
执行python pyperformance基准测试的步骤
开发语言·python
chushiyunen1 小时前
python中的for循环、dict、set、列表、数组等
开发语言·python
sqyno1sky1 小时前
数据分析与科学计算
jvm·数据库·python