1巫员,創(chuàng)建待改的表格格式,命名為m_strings.xlsx,文檔里的格式如下
語言
鍵
修改的值
cn
app_name
lalal
eu
app_name
ai_aaa
fr
app_name
ai_lalalala
2,將m_strings.xlsx放在xxx目錄下脓鹃,在xxx目錄下創(chuàng)建cn,eu,fr等文件夾,將對應的strings.xml文件放到對應目錄下
3古沥,執(zhí)行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()