iOS 多语言使用python生成文件

import openpyxl

def process_excel(excel_file):
    workbook = openpyxl.load_workbook(excel_file)
    sheet = workbook.active

    # 获取标题行
    titles = [cell.value for cell in sheet[1]]

    # 创建对应的txt文件
    for title in titles:
        if title:
            with open(f"{title}.txt", "w", encoding="utf-8") as txt_file:
                for row in sheet.iter_rows(min_row=2, values_only=True):
                    key = row[0]
                    value = row[titles.index(title) + 1]
                    value = value.replace('"', '\"')  # 对 value 中的双引号进行转义
                    txt_file.write(f'"{key}" = "{value}";\n')

if __name__ == "__main__":
    process_excel("your_excel_file.xlsx")

excel表格的格式标准

中文 英文 德文
你好 hello dHello
go dGo

执行文件后会自动生成对应的.txt文件
上面的excel会生成如下的三个文件,然后需要自己修改一下文件名字:
中文.txt
英文.txt
德文.txt

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容