【SDL Trados Studio】sdltm格式转excel

思路

1.sdltm转tmx(SDL Trados Studio)

2.tmx转excel(代码/Xbench/Maxprograms/Localazy)

步骤

1.利用SDL Trados Studio打开sdltm文件

2.将选择要导出的翻译库,右键导出

3.查看tmx文件,发现tmx文件符合xml文件格式

4.利用python将tmx文件转为excel文件

代码

python 复制代码
import pandas as pd
import xml.etree.ElementTree as ET
def get_text_for_tag(root):
    texts = []
    for element in root.iter():
        if element.text:
            texts.append(element.text)
        if element.tail and element.tail != "\n      ":
            texts.append(element.tail)
    return ''.join(texts)
def tmx_to_excel(tmx_file, excel_file):
    tree = ET.parse(tmx_file)
    root = tree.getroot()
    # 初始化数据列表
    data = []
    # 遍历TMX文件中的每个tu(翻译单元)
    for tu in root.findall('.//tu'):
        seglist = tu.findall("tuv/seg")
        source_text = get_text_for_tag(seglist[0])
        target_text = get_text_for_tag(seglist[1])
        data.append([source_text, target_text])
    # 创建DataFrame
    df = pd.DataFrame(data, columns=['Source', 'Target'])
    # 导出为Excel文件
    df.to_excel(excel_file, index=False)
# 使用示例
tmx_to_excel(r'tmx文件路径', r'xlsx文件路径')

结果

相关推荐
Non-existent9872 天前
WPS批量清理单元格空白字符的4种方法-异常数字格式处理-实战
excel·wps
Channing Lewis3 天前
PHP 解析 Excel 的那些坑:一次“行号错位”引发的数据丢失
开发语言·php·excel
jarreyer3 天前
【数据分析绘图】excel绘图和bi工具区别
数据挖掘·数据分析·excel
chatexcel3 天前
ChatExcel Max使用教程:图片、PDF、网页与复杂Excel的一站式数据分析
数据分析·pdf·excel
cngkqy3 天前
excel从某一列中用match筛选匹配的数据
excel
qq_546937273 天前
Excel批量转PDF_Word_图片,支持自动合并报表,效率翻倍。
pdf·word·excel
ai_coder_ai3 天前
在自动化脚本中操作excel文件
运维·自动化·excel
三千花灯3 天前
【Playwright】 自动化测试之参数化登录(Excel/CSV 数据源)
人工智能·机器学习·excel
罗政3 天前
AI工作流实现Excel全自动化(支持SQL)-案例:医院门诊排班表
人工智能·自动化·excel
小妖6663 天前
excel 怎么在单元格内容自动加上一段文字不能用公式
excel·vba