def open_all_excel():
lang_col_mapper = get_lang_col_mapper()
# xlApp = client.Dispatch("Excel.Application")
for lang_key, _ in lang_col_mapper.items():
# print(lang_key)
# if "en" not in lang_key:
# continue
file_dir = os.path.join(datasheetDir, lang_key)
file_list = walkFile(file_dir)
count_num = 0
xlApp = client.Dispatch("Excel.Application")
for file_name in file_list:
count_num += 1
if file_name.startswith("~"):
continue
if not (file_name.endswith(".xlsx")):
continue
excel_file = f"/{lang_key}/{file_name}"
file_src = os.path.join(datasheetDir, lang_key,file_name)
file_src = change_path_platform(file_src=file_src)
# xlApp = client.Dispatch("Excel.Application")
try:
xlApp.Visible = False
except:
try:
xlApp.Visible = False
except:
try:
xlApp.Visible = False
except:
xlApp.Visible = False
books = xlApp.Workbooks.Open(file_src)
xlApp.DisplayAlerts = False
logger.info(f"第{_-4}语言 {lang_key} {count_num} {file_src}已重新打开")
try:
books.SaveAs(file_src)
except Exception as e:
print(f"ERROR : {file_src} {e}")
books.Close()
xlApp.DisplayAlerts = True
xlApp.Quit()
kill()
time.sleep(5)