# -*- coding: UTF-8 -*- import sys import openpyxl import re def process(path,key,color): workbook = openpyxl.load_workbook(path) sheet = workbook["Sheet1"] row_num = sheet.max_row #行数 column_num = sheet.max_column #列数 start_row = 4 #第三行开始语言表内容 keyword_column = 2 #第二列是关键字列 lang_column = 3 #第三列开始语言列 regex = re.compile(r"(\d+?%)"); for row_index in range(start_row,row_num): keyword = sheet.cell(row_index,keyword_column).value if keyword.startswith(key): print("修改的翻译字段为:",keyword) for column_index in range(lang_column,column_num): cell = sheet.cell(row_index,column_index) content = cell.value if content: # print("修改前: ",content) matches = regex.findall(content) if matches: for match in matches: value = match content = content.replace(value,f"{value}") # print("修改后: ",content) cell.value = content workbook.save(path) workbook.close() if __name__ == "__main__": if len(sys.argv) < 4: print("参数不对,请传入正确的参数") exit(-1) path = sys.argv[1] key = sys.argv[2] color = sys.argv[3] process(path,key,color)