1,创建待改的表格格式,命名为m_strings.xlsx,文档里的格式如下
语言
键
修改的值
cn
app_name
lalal
eu
app_name
ai_aaa
fr
app_name
ai_lalalala
2,将m_strings.xlsx放在xxx目录下,在xxx目录下创建cn,eu,fr等文件夹,将对应的strings.xml文件放到对应目录下
3,执行asstrings.py
附代码
from openpyxl import load_workbook
import sys
import os
import xml.etree.ElementTree as ET
def open():
path = sys.path[0]+"\\strings\\m_strings.xlsx"
data_excel = load_workbook(path)
sheet = data_excel.worksheets[0]
columns = sheet.rows
for row in columns:
co_val = [row.value for row in row]
sub_path = sys.path[0]+"\\strings\\"+co_val[0]+"\\"
if os.path.exists(sub_path):
update(sub_path,co_val[1],co_val[2])
def update(path,key,m_value):
#打开xml文档
print('path='+path+",key="+key+",value="+m_value)
xml_path = path+'strings.xml'
dom = ET.parse(xml_path)
# 获取根元素
root = dom.getroot()
# 获取string列表
resource = root.findall('string')
for node in resource:
# 得到名称
name = node.get('name')
# 得到对应的值
value = node.text
if key == name:
node.text = m_value
print('node:'+node.text)
dom.write(xml_path,encoding='utf-8')
if __name__=='__main__':
open()