diff --git "a/a000_\345\273\272\347\253\213\346\263\250\351\237\263\346\252\224\346\241\210.py" "b/a000_\345\273\272\347\253\213\346\263\250\351\237\263\346\252\224\346\241\210.py" deleted file mode 100644 index a6f4a56..0000000 --- "a/a000_\345\273\272\347\253\213\346\263\250\351\237\263\346\252\224\346\241\210.py" +++ /dev/null @@ -1,5 +0,0 @@ -# 產生注音檔:Piau-Tsu-Im.xlsx -from p000_san_sing_tsu_im_tong import main as san_sin_tsu_im_tong - -# 「產生注音檔」開始作業 -san_sin_tsu_im_tong() diff --git "a/a100_\344\272\210\346\210\221\346\274\242\345\255\227\346\263\250\351\237\263.py" "b/a100_\344\272\210\346\210\221\346\274\242\345\255\227\346\263\250\351\237\263.py" deleted file mode 100644 index b73dee4..0000000 --- "a/a100_\344\272\210\346\210\221\346\274\242\345\255\227\346\263\250\351\237\263.py" +++ /dev/null @@ -1,110 +0,0 @@ -import getopt -import sys -import os - -import xlwings as xw - -import settings -from p000_import_source_data import main_run as san_sing_han_ji_tsu_im_paiau -# from p100_tsa_ji_tian import main_run as tsa_ji_tian_tshue_tsu_im -# from p200_hoo_gua_tsu_im import main_run as hoo_gua_tsu_im -from p100_tsa_nga_siok_thong_ji_tian import main_run as tsa_ji_tian_tshue_tsu_im -from p200_Iong_Nga_Siok_Thong_Zu_Im import main_run as hoo_gua_tsu_im - - -def myfunc(argv): - arg_input = "" - arg_output = "" - arg_user = "" - arg_help = "{0} -i -u -o ".format(argv[0]) - - try: - opts, args = getopt.getopt( # pyright: ignore - argv[1:], "hi:u:o:", ["help", "input=", "user=", "output="] - ) - except Exception as e: - print(e) - print(arg_help) - sys.exit(2) - - for opt, arg in opts: - if opt in ("-h", "--help"): - print(arg_help) # print the help message - sys.exit(2) - elif opt in ("-i", "--input"): - arg_input = arg - elif opt in ("-u", "--user"): - arg_user = arg - elif opt in ("-o", "--output"): - arg_output = arg - - print("input:", arg_input) - print("user:", arg_user) - print("output:", arg_output) - - return { - "input": arg_input, - "user": arg_user, - "output": arg_output, - } - - -if __name__ == "__main__": - # ========================================================================= - # (1) 取得需要注音的「檔案名稱」及其「目錄路徑」。 - # ========================================================================= - # 取得 Input 檔案名稱 - file_path = settings.get_input_file_path() - if not file_path: - print("未設定 .env 檔案") - # sys.exit(2) - opts = myfunc(sys.argv) - if opts["input"] != "": - CONVERT_FILE_NAME = opts["input"] - else: - CONVERT_FILE_NAME = "Piau-Tsu-Im" - else: - CONVERT_FILE_NAME = file_path - print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") - - # ========================================================================= - # (2) 將存放在「工作表1」的「漢字」文章,製成「漢字注音表」以便填入注音。 - # ========================================================================= - san_sing_han_ji_tsu_im_paiau(CONVERT_FILE_NAME) - - # ========================================================================= - # (3) 在字典查注音,填入漢字注音表。 - # ========================================================================= - tsa_ji_tian_tshue_tsu_im(CONVERT_FILE_NAME) - - # ========================================================================= - # (4) 將已注音之「漢字注音表」,製作成 HTML 格式之「注音/拼音/標音」網頁。 - # ========================================================================= - hoo_gua_tsu_im(CONVERT_FILE_NAME) - - # ========================================================== - # 檢查「缺字表」狀態 - # ========================================================== - # 指定來源工作表 - source_sheet = xw.Book(CONVERT_FILE_NAME).sheets["缺字表"] - # 取得工作表內總列數 - end_row_no = ( - source_sheet.range("A" + str(source_sheet.cells.last_cell.row)).end("up").row - ) - if end_row_no > 1: - print(f"總計字典查不到注音的漢字共:{end_row_no}個。") - - # ========================================================================= - # (5) 依據《文章標題》另存新檔。 - # ========================================================================= - wb = xw.Book(CONVERT_FILE_NAME) - setting_sheet = wb.sheets["env"] - new_file_name = str( - setting_sheet.range("C4").value - ).strip() - new_file_path = os.path.join( - ".\\output", - f"【河洛話注音】{new_file_name}" + ".xlsx") - - # 儲存新建立的工作簿 - wb.save(new_file_path) diff --git "a/a200_\346\274\242\345\255\227\350\243\234\346\263\250\351\237\263.py" "b/a200_\346\274\242\345\255\227\350\243\234\346\263\250\351\237\263.py" deleted file mode 100644 index ae547c3..0000000 --- "a/a200_\346\274\242\345\255\227\350\243\234\346\263\250\351\237\263.py" +++ /dev/null @@ -1,96 +0,0 @@ -import getopt -import os -import sys -import xlwings as xw - -from dotenv import dotenv_values - -from p110_khuat_ji_poo_tsu_im import main_run as poo_tsu_im -from p200_hoo_gua_tsu_im import main_run as hoo_gua_tsu_im - -def myfunc(argv): - arg_input = "" - arg_output = "" - arg_user = "" - arg_help = "{0} -i -u -o ".format(argv[0]) - - try: - opts, args = getopt.getopt( - argv[1:], "hi:u:o:", ["help", "input=", "user=", "output="] - ) - except getopt.GetoptError: - print(arg_help) - sys.exit(2) - - for opt, arg in opts: - if opt in ("-h", "--help"): - print(arg_help) # print the help message - sys.exit(2) - elif opt in ("-i", "--input"): - arg_input = arg - elif opt in ("-u", "--user"): - arg_user = arg - elif opt in ("-o", "--output"): - arg_output = arg - - print("input:", arg_input) - print("user:", arg_user) - print("output:", arg_output) - - return { - "input": arg_input, - "user": arg_user, - "output": arg_output, - } - - -if __name__ == "__main__": - # 取得 Input 檔案名稱 - config = dotenv_values(".env") - dir_path = str(config["INPUT_FILE_PATH"]) - file_name = str(config["FILE_NAME"]) - file_path = os.path.join(dir_path, file_name) - if not file_path: - print("未設定 config.env 檔案") - # sys.exit(2) - opts = myfunc(sys.argv) - if opts["input"] != "": - CONVERT_FILE_NAME = opts["input"] - else: - CONVERT_FILE_NAME = "Piau-Tsu-Im.xlsx" - else: - CONVERT_FILE_NAME = file_path - print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") - - # 將「漢字注音表」的「台羅注音」拆解出聲母、韻母及聲調 - poo_tsu_im(CONVERT_FILE_NAME) - - # 將已填入注音之「漢字注音表」,製作成 HTML 格式的各式「注音/拼音/標音」。 - hoo_gua_tsu_im(CONVERT_FILE_NAME) - - # ========================================================== - # 檢查「缺字表」狀態 - # ========================================================== - # 指定來源工作表 - source_sheet = xw.Book(CONVERT_FILE_NAME).sheets["缺字表"] - # 取得工作表內總列數 - end_row_no = ( - source_sheet.range("A" + str(source_sheet.cells.last_cell.row)).end("up").row - ) - if end_row_no > 1: - print(f"此次增補注音的漢字總數共:{end_row_no}個。") - - # =========================================================================== - # 依據《文章標題》另存新檔。 - # =========================================================================== - wb = xw.Book(CONVERT_FILE_NAME) - setting_sheet = wb.sheets["env"] - new_file_name = str( - setting_sheet.range("C4").value - ).strip() - new_file_path = os.path.join( - ".\\output", - f"【河洛話注音】{new_file_name}" + ".xlsx") - - # 儲存新建立的工作簿 - wb.save(new_file_path) \ No newline at end of file diff --git "a/a520_\350\243\275\344\275\234\346\263\250\351\237\263\347\266\262\351\240\201.py" "b/a520_\350\243\275\344\275\234\346\263\250\351\237\263\347\266\262\351\240\201.py" deleted file mode 100644 index d7f5f23..0000000 --- "a/a520_\350\243\275\344\275\234\346\263\250\351\237\263\347\266\262\351\240\201.py" +++ /dev/null @@ -1,105 +0,0 @@ -import os -import sqlite3 -import sys - -import xlwings as xw - -import settings -from mod_file_access import ( - San_Sing_Han_Ji_Zu_Im_Piau, - close_excel_file, - get_cmd_input, - open_excel_file, - save_to_a_working_copy, - write_to_excel_file, -) -from mod_廣韻 import init_sing_bu_dict, init_un_bu_dict -from p501_Kong_Un_Cha_Ji_Tian import Kong_Un_Piau_Im -from p502_TLPA_Cu_Im import Iong_TLPA_Cu_Im - - -def initialize_dicts(db_cursor): - """初始化聲母和韻母對照表字典""" - try: - sing_bu_dict = init_sing_bu_dict(db_cursor) - un_bu_dict = init_un_bu_dict(db_cursor) - print("字典初始化完成。") - except Exception as e: - print(f"字典初始化失敗:{e}") - sys.exit(1) - return sing_bu_dict, un_bu_dict - - -def create_annotation_file(wb, db_cursor): - """建立注音表並進行查詢填寫""" - # 建立漢字注音表 - San_Sing_Han_Ji_Zu_Im_Piau(wb.name) - # # 查詢注音並填寫表格 - # Kong_Un_Piau_Im(wb.name, db_cursor) - - -def export_to_html(wb): - """將已注音的漢字注音表導出為 HTML 格式""" - # 這裡可以使用已經填寫的漢字注音表進行轉換 - print("將注音表轉換為 HTML 格式的功能可以在這裡實現。") - - -def main(): - #------------------------------------------------------------------------- - # 使用已打開且處於作用中的 Excel 工作簿 - #------------------------------------------------------------------------- - # 取得專案根目錄。 - try: - wb = xw.apps.active.books.active - except Exception as e: - print(f"發生錯誤: {e}") - print("無法找到作用中的 Excel 工作簿") - sys.exit(2) - - # 獲取活頁簿的完整檔案路徑 - file_path = wb.fullname - print(f"完整檔案路徑: {file_path}") - - # 獲取活頁簿的檔案名稱(不包括路徑) - file_name = wb.name - print(f"檔案名稱: {file_name}") - - # 資料庫連接 - DATABASE = settings.get_database_path() - with sqlite3.connect(DATABASE) as conn: - db_cursor = conn.cursor() - print(f"DATABASE = {DATABASE}") - - # # 取得命令列參數和檔案路徑 - # opts = get_cmd_input() - # CONVERT_FILE_NAME = opts["input"] - # dir_path = opts["dir_path"] - # print(f"處理檔案: {CONVERT_FILE_NAME}") - - # # 開啟指定的 Excel 檔案 - # wb = open_excel_file(dir_path, CONVERT_FILE_NAME) - # if wb is None: - # print("無法開啟檔案,終止程式執行。") - # sys.exit() - - # 初始化字典 - sing_bu_dict, un_bu_dict = initialize_dicts(db_cursor) - - # 創建漢字注音表並查詢注音 - create_annotation_file(wb, db_cursor) - - # 注音轉換處理 - Iong_TLPA_Zu_Im(wb, sing_bu_dict, un_bu_dict) - - # 檢查缺字表狀態 - source_sheet = wb.sheets["缺字表"] - end_row_no = source_sheet.range("A" + str(source_sheet.cells.last_cell.row)).end("up").row - if end_row_no > 1: - print(f"總計字典查不到注音的漢字共:{end_row_no}個。") - - # 儲存 Excel 檔案並關閉 - write_to_excel_file(wb) - close_excel_file(wb) - -if __name__ == "__main__": - main() diff --git "a/a520_\350\243\275\344\275\234\346\263\250\351\237\263\347\266\262\351\240\201_bak.py" "b/a520_\350\243\275\344\275\234\346\263\250\351\237\263\347\266\262\351\240\201_bak.py" deleted file mode 100644 index 29ef926..0000000 --- "a/a520_\350\243\275\344\275\234\346\263\250\351\237\263\347\266\262\351\240\201_bak.py" +++ /dev/null @@ -1,100 +0,0 @@ -#================================================================ -# 《予我廣韻標音》 -# 使用《廣韻》作為漢字標讀音之依據。 -#================================================================ -import getopt -import os -import sqlite3 -import sys - -import xlwings as xw - -import settings -from mod_file_access import ( - close_excel_file, - get_cmd_input, - open_excel_file, - save_to_a_working_copy, - write_to_excel_file, -) -from mod_廣韻_v3 import init_sing_bu_dict, init_un_bu_dict -from p500_Import_Source_Sheet import San_Sing_Han_Ji_Tsh_Im_Piau -from p501_Kong_Un_Cha_Ji_Tian import Kong_Un_Piau_Im -from p502_TLPA_Cu_Im import Iong_TLPA_Zu_Im - - -def main(): - # ==========================================================" - # 資料庫", - # ==========================================================" - # 自 .env 檔案取得資料庫名稱 - DATABASE = settings.get_database_path() - conn = sqlite3.connect(DATABASE) - db_cursor = conn.cursor() - print(f"DATABASE = {DATABASE}") - - # ========================================================================= - # (1) 取得需要注音的「檔案名稱」及其「目錄路徑」。 - # ========================================================================= - # 自命令列取得 Input 檔案名稱 - opts = get_cmd_input() - CONVERT_FILE_NAME = opts["input"] - print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") - - # 取得檔案所屬之目錄路徑 - dir_path = opts["dir_path"] - - # 指定提供來源的【檔案】 - wb = open_excel_file(dir_path, CONVERT_FILE_NAME) - if wb is None: - print("無法開啟檔案,終止程式執行。") - sys.exit() - - # ========================================================================= - # (2) 建置「漢字注音表」 - # 將存放在「工作表1」的「漢字」文章,製成「漢字注音表」以便填入注音。 - # ========================================================================= - # San_Sing_Han_Ji_Tsh_Im_Piau(CONVERT_FILE_NAME) - - # ========================================================================= - # (3) 在字典查注音,填入漢字注音表。 - # ========================================================================= - # Kong_Un_Piau_Im(CONVERT_FILE_NAME, db_cursor) - - # ========================================================================= - # (4) 將已注音之「漢字注音表」,製作成 HTML 格式之「注音/拼音/標音」網頁。 - # ========================================================================= - - # 設定聲母及韻母之注音對照表 - try: - sing_bu_dict = init_sing_bu_dict(db_cursor) - un_bu_dict = init_un_bu_dict(db_cursor) - except Exception as e: - print(e) - Iong_TLPA_Cu_Im(wb, sing_bu_dict, un_bu_dict) - - # ========================================================== - # 檢查「缺字表」狀態 - # ========================================================== - # 指定來源工作表 - source_sheet = wb.sheets["缺字表"] - # 取得工作表內總列數 - end_row_no = ( - source_sheet.range("A" + str(source_sheet.cells.last_cell.row)).end("up").row - ) - if end_row_no > 1: - print(f"總計字典查不到注音的漢字共:{end_row_no}個。") - - # ========================================================================= - # (5) 依據《文章標題》另存新檔。 - # ========================================================================= - write_to_excel_file(wb) - close_excel_file(wb) - - # ========================================================== - # 關閉資料庫 - # ========================================================== - conn.close() - -if __name__ == "__main__": - main() \ No newline at end of file diff --git "a/a600_\346\274\242\345\255\227\346\237\245\345\273\243\351\237\273\346\223\254\351\237\263_Excel.py" "b/a600_\346\274\242\345\255\227\346\237\245\345\273\243\351\237\273\346\223\254\351\237\263_Excel.py" deleted file mode 100644 index 562554f..0000000 --- "a/a600_\346\274\242\345\255\227\346\237\245\345\273\243\351\237\273\346\223\254\351\237\263_Excel.py" +++ /dev/null @@ -1,103 +0,0 @@ -#============================================================================== -# 透過 Excel ,使用廣韻的反切方法,查找漢字的羅馬拼音。 -# -# 操作方式: -# - 輸入欲查詢羅馬拼音之漢字; -# - 輸入廣韻的查找索引資料。 -# -# ipython a900_廣韻反切查羅馬拼音.ipynb 攝 "書涉 (《廣韻·入聲·葉·攝》)" -#============================================================================== - -import sys - -import xlwings as xw - -from __mod_huan_tshiat import tshu_tiau -from mod_於字典網站查詢漢字之廣韻切語發音 import fetch_kong_un_info - - -def fetch_arg(): - # 取得命令行參數 - cmd_arg = sys.argv[1:] # 取得所有除腳本名稱之外的命令行參數 - - # 檢查 cmd_arg 是否有內容 - if not cmd_arg: # 如果沒有傳入任何參數 - print("沒有傳入任何參數,使用預設參數。") - # else: - # # 無論是否使用預設參數,都遍歷 cmd_arg 中的每個元素 - # for i, arg in enumerate(cmd_arg, start=1): - # print(f"參數 {i}: {arg}") - # else: - # # 如果沒有傳入任何參數,則顯示提示信息,然後終止程式 - # print("請輸入欲查詢《廣韻》切語之漢字。") - # sys.exit(1) - - # 若使用者未輸入欲查詢之漢字,則賦予預設值 - han_ji = cmd_arg[0] if len(cmd_arg) > 0 else "詼" - print(f"han_ji = {han_ji}") - - return han_ji - - - -# 程式作業流程: -# 1. 欲查詢之漢字,如:詼; -# 2. 反切雙字,如:苦回; -# 3. 廣韻查詢索引:廣韻·上平聲·灰·恢; -# 4. 自反切雙字分離出:反切上字、反切下字,如:反切上字=苦、反切下字=回。 -if __name__ == "__main__": - # 取得使用者輸入的參數 - han_ji = fetch_arg() - - # 取得反切語與四聲調類 - tshiat_gu_list = fetch_kong_un_info(han_ji) - - ## 開啟可執行反切查羅馬拼音之活頁簿檔案 - # 1. 開啟 Excel 活頁簿檔案: .\tools\廣韻反切查音工具.xlsx ; - # 2. 擇用 "反切" 工作表。 - # - # [程式規格]: - # - 使用 xlwings 套件,操作 Excel 檔案; - # - 以上兩步的作業程序,都用 try: exception: 形式執行,遇有意外事件發生時,於畫面顯示問題狀況,然後終止程式的繼續執行。 - - try: - # 指定 Excel 檔案路徑 - file_path = r'.\\tools\\廣韻反切查音工具.xlsx' - - # 使用 xlwings 開啟 Excel 檔案 - wb = xw.Book(file_path) - - # 選擇名為 "反切" 的工作表 - sheet = wb.sheets['反切'] - - # 將變數值填入指定的儲存格 - sheet.range('C2').value = han_ji - for item in tshiat_gu_list: - # 將漢字之切語填入指定的儲存格 - sheet.range('D2').value = item["tshiat_gu"] - # 將切語上字填入指定的儲存格 - sheet.range('C5').value = siong_ji = item["tshiat_gu"][0] - # 將切語下字填入指定的儲存格 - sheet.range('C6').value = ha_ji = item["tshiat_gu"][1] - # 將切語下字所屬之四聲調類填入指定的儲存格 - sheet.range('E6').value = tshu_tiau(item["tiau"]) - - # 從 D8 儲存格取出值,存放於變數 tai_lo_phing_im - tai_lo_phing_im = sheet.range('D8').value - - #======================================================= - # 顯示查詢結果 - #======================================================= - print("\n===================================================") - print(f"查詢漢字:{han_ji}\t廣韻切語為: {item['tshiat_gu']}\t台羅拼音為: {tai_lo_phing_im}") - print(f"反切上字:{siong_ji}\t得聲母台羅拼音為: {sheet.range('D5').value}\t分清濁為:{sheet.range('E5').value}") - print(f"反切下字:{ha_ji}\t得韻母台羅拼音為: {sheet.range('D6').value}\t辨四聲為:{sheet.range('E6').value}聲") - if not sheet.range('D7').value == "找不到": - print(f"依分清濁與辨四聲,得聲調為:{sheet.range('E7').value},即:台羅四聲八調之第 {int(sheet.range('D7').value)} 調") - - except Exception as e: - # 如果遇到任何錯誤,顯示錯誤信息並終止程式 - print(f"發生錯誤:{e}") - - - diff --git "a/a600_\346\274\242\345\255\227\346\237\245\345\273\243\351\237\273\346\223\254\351\237\263_SQLite.py" "b/a600_\346\274\242\345\255\227\346\237\245\345\273\243\351\237\273\346\223\254\351\237\263_SQLite.py" deleted file mode 100644 index d3d2f4b..0000000 --- "a/a600_\346\274\242\345\255\227\346\237\245\345\273\243\351\237\273\346\223\254\351\237\263_SQLite.py" +++ /dev/null @@ -1,102 +0,0 @@ -#============================================================================== -# 透過 Excel ,使用廣韻的反切方法,查找漢字的羅馬拼音。 -# -# 操作方式: -# - 輸入欲查詢羅馬拼音之漢字; -# - 輸入廣韻的查找索引資料。 -# -# ipython a900_廣韻反切查羅馬拼音.ipynb 攝 "書涉 (《廣韻·入聲·葉·攝》)" -#============================================================================== - -import sys - -from __mod_huan_tshiat import query_tiau_ho, tshu_tiau -from __mod_Query_for_Tshiat_Gu import query_tshiat_gu_ha_ji, query_tshiat_gu_siong_ji -from mod_於字典網站查詢漢字之廣韻切語發音 import fetch_kong_un_info - - -def fetch_arg(): - # 取得命令行參數 - cmd_arg = sys.argv[1:] # 取得所有除腳本名稱之外的命令行參數 - - # 檢查 cmd_arg 是否有內容 - if not cmd_arg: # 如果沒有傳入任何參數 - print("沒有傳入任何參數,使用預設參數。") - - # 若使用者未輸入欲查詢之漢字,則賦予預設值 - han_ji = cmd_arg[0] if len(cmd_arg) > 0 else "詼" - print(f"han_ji = {han_ji}") - - return han_ji - -# 程式作業流程: -# 1. 欲查詢之漢字,如:詼; -# 2. 反切雙字,如:苦回; -# 3. 廣韻查詢索引:廣韻·上平聲·灰·恢; -# 4. 自反切雙字分離出:反切上字、反切下字,如:反切上字=苦、反切下字=回。 -if __name__ == "__main__": - # 取得使用者輸入的參數 - han_ji = fetch_arg() - - # 自廣韻線上字典,取得反切語與四聲調類 - # 查詢回傳的結果是一個字典陣列,每個字典包含了反切語、四聲調類、韻系、反切下字等資訊 - # tshiat_gu_item = { - # "tshiat_gu": tshiat_gu, # 切語:苦回 - # "tiau": tiau, # 調:平/上/去/入的四聲調類 - # "un_he": un_he, # 韻系:灰 - # "tshia_gu_ha_ji": tshia_gu_ha_ji, # 切語下字:恢 - # } - tshiat_gu_list = fetch_kong_un_info(han_ji) - - #======================================================= - # 顯示查詢結果 - #======================================================= - print("\n===================================================") - print(f"查詢漢字:{han_ji}") - for item in tshiat_gu_list: - # 取得切語 - tshiat_gu = item["tshiat_gu"] - - # 查詢切語上字 - siong_ji = item["tshiat_gu"][0] - tshiat_gu_siong_ji = query_tshiat_gu_siong_ji(siong_ji) - if not tshiat_gu_siong_ji: - print("---------------------------------------------------") - print(f"廣韻切語: {tshiat_gu}\t找不到切語上字:{siong_ji}") - continue - - tai_lo_siann_bu = tshiat_gu_siong_ji[0]["tai_lo"] - tshing_tok = tshiat_gu_siong_ji[0]["tshing_tok"] - - # 查詢切語下字 - ha_ji = item["tshiat_gu"][1] - tshiat_gu_ha_ji = query_tshiat_gu_ha_ji(ha_ji) - if not tshiat_gu_ha_ji: - print("---------------------------------------------------") - print(f"廣韻切語: {tshiat_gu}\t找不到切語下字:{ha_ji}") - continue - - tai_lo_un_bu = tshiat_gu_ha_ji[0]["tai_lo"] - - # 取得四聲調類 - tiau_lui = item["tiau"] - su_sing = tshu_tiau(tiau_lui) - # 查詢反切語之四聲八調之調號 - tiau_ho = query_tiau_ho(tshing_tok, su_sing) - - # 組合台羅拼音 - tai_lo_phing_im = f"{tai_lo_siann_bu}{tai_lo_un_bu}{tiau_ho}" - - #======================================================= - # 顯示查詢結果 - #======================================================= - print("---------------------------------------------------") - print(f"廣韻切語: {tshiat_gu}\t台羅拼音: {tai_lo_phing_im}") - print(f"反切上字:{siong_ji}\t得聲母台羅拼音為: {siong_ji}\t分清濁為:{tshing_tok}") - print(f"反切下字:{ha_ji}\t得韻母台羅拼音為: {ha_ji}\t辨四聲為:{su_sing}聲") - print(f"依分清濁與辨四聲,得聲調為:{tshing_tok[-1]}{su_sing},即:台羅四聲八調之第 {tiau_ho} 調") - # if not sheet.range('D7').value == "找不到": - # print(f"依分清濁與辨四聲,得聲調為:{sheet.range('E7').value},即:台羅四聲八調之第 {int(sheet.range('D7').value)} 調") - - - diff --git "a/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263.py" "b/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263.py" index 3e9a963..33bc8cd 100644 --- "a/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263.py" +++ "b/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263.py" @@ -13,6 +13,7 @@ # 載入自訂模組 from mod_excel_access import ( + delete_sheet_by_name, get_han_ji_khoo, get_tai_gi_by_han_ji, get_value_by_name, @@ -63,6 +64,60 @@ def logging_process_step(msg): # ========================================================================= # 作業程序 # ========================================================================= +def reset_han_ji_cells(wb, sheet_name='漢字注音'): + sheet = wb.sheets[sheet_name] + sheet.activate() + + # 設定起始及結束的【列】位址(【第5列】、【第9列】、【第13列】等列) + TOTAL_LINES = int(wb.names['每頁總列數'].refers_to_range.value) + ROWS_PER_LINE = 4 + start_row = 5 + end_row = start_row + (TOTAL_LINES * ROWS_PER_LINE) + + # 設定起始及結束的【欄】位址(【D欄=4】到【R欄=18】) + CHARS_PER_ROW = int(wb.names['每列總字數'].refers_to_range.value) + start_col = 4 + end_col = start_col + CHARS_PER_ROW + + # 重設【漢字】儲存格文字及底色格式 + EOF = False + line = 1 + for row in range(start_row, end_row, ROWS_PER_LINE): + # 若已到【結尾】或【超過總行數】,則跳出迴圈 + if EOF or line > TOTAL_LINES: + break + + # 設定【作用儲存格】為列首 + Two_Empty_Cells = 0 + sheet.range((row, 1)).select() + + # 逐欄取出漢字處理 + for col in range(start_col, end_col): + cell_value = sheet.range((row, col)).value + if cell_value == 'φ': + EOF = True + break + elif cell_value == '\n': + break + elif cell_value == None: + if Two_Empty_Cells == 0: + Two_Empty_Cells += 1 + elif Two_Empty_Cells == 1: + EOF = True + break + else: + sheet.range((row, col)).font.color = (0, 0, 0) # 將文字顏色設為【黑色】 + sheet.range((row, col)).color = (255, 255, 255) # 將底色設為【白色】 + + # 若讀到【換行】或【文字終結】,跳出逐欄取字迴圈 + if cell_value == '\n' or EOF: + break + + # 每當處理一行 15 個漢字後,亦換到下一行 + line += 1 + row += 4 + + def ca_ji_kiat_ko_tng_piau_im(result, han_ji_khoo: str, piau_im: PiauIm, piau_im_huat: str): """查字結果出標音:查詢【漢字庫】取得之【查找結果】,將之切分:聲、韻、調""" if han_ji_khoo == "河洛話": @@ -111,24 +166,36 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', ue_im_lui_piat=" cursor = conn.cursor() # 建置 PiauIm 物件,供作漢字拼音轉換作業 - han_ji_khoo = get_value_by_name(wb=wb, name='漢字庫') - piau_im = PiauIm(han_ji_khoo=han_ji_khoo) - piau_im_huat = get_value_by_name(wb=wb, name='標音方法') + han_ji_khoo_field = '漢字庫' + han_ji_khoo_name = get_value_by_name(wb=wb, name=han_ji_khoo_field) + piau_im = PiauIm(han_ji_khoo=han_ji_khoo_name) # 指定漢字自動查找使用的【漢字庫】 + piau_im_huat = get_value_by_name(wb=wb, name='標音方法') # 指定【台語音標】轉換成【漢字標音】的方法 + + # 建置自動及人工漢字標音字庫工作表:(1)【漢字庫工作表】;(2)【人工標音字庫工作表】;(3)【缺字表】 + piau_im_sheet_name = '標音字庫' + delete_sheet_by_name(wb=wb, sheet_name=piau_im_sheet_name) + han_ji_koo_sheet = get_han_ji_khoo(wb=wb, sheet_name=piau_im_sheet_name) - # 建置自動及人工漢字標音字庫工作表:(1)【漢字庫工作表】;(2)【人工標音字庫工作表】 - han_ji_koo_sheet = get_han_ji_khoo(wb=wb, sheet_name='漢字庫') - jin_kang_piau_im = get_han_ji_khoo(wb=wb, sheet_name='人工標音字庫') + jin_kang_piau_im_sheet_name='人工標音字庫' + delete_sheet_by_name(wb=wb, sheet_name=jin_kang_piau_im_sheet_name) + jin_kang_piau_im_sheet = get_han_ji_khoo(wb=wb, sheet_name=jin_kang_piau_im_sheet_name) + + khuat_ji_piau_name = '缺字表' + delete_sheet_by_name(wb=wb, sheet_name=khuat_ji_piau_name) + khuat_ji_piau_sheet = get_han_ji_khoo(wb=wb, sheet_name=khuat_ji_piau_name) # 指定【漢字注音】工作表為【作用工作表】 sheet = wb.sheets[sheet_name] sheet.activate() + # 重設【漢字】儲存格文字及底色格式 + reset_han_ji_cells(wb=wb) + # 設定起始及結束的【列】位址(【第5列】、【第9列】、【第13列】等列) TOTAL_LINES = int(wb.names['每頁總列數'].refers_to_range.value) ROWS_PER_LINE = 4 start_row = 5 end_row = start_row + (TOTAL_LINES * ROWS_PER_LINE) - line = 1 # 設定起始及結束的【欄】位址(【D欄=4】到【R欄=18】) CHARS_PER_ROW = int(wb.names['每列總字數'].refers_to_range.value) @@ -137,6 +204,7 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', ue_im_lui_piat=" # 逐列處理作業 EOF = False + line = 1 for row in range(start_row, end_row, ROWS_PER_LINE): # 若已到【結尾】或【超過總行數】,則跳出迴圈 if EOF or line > TOTAL_LINES: @@ -211,13 +279,13 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', ue_im_lui_piat=" han_ji_u_piau_im = True # 將人工輸入的【台語音標】置入【破音字庫】Dict - maintain_han_ji_koo(sheet=jin_kang_piau_im, + maintain_han_ji_koo(sheet=jin_kang_piau_im_sheet, han_ji=han_ji, tai_gi=tai_gi_im_piau, show_msg=False) else: # 無人工輸入,則自【漢字庫】查找作業 # 查找【人工標音字庫】,確認是否有此漢字 - tai_gi_im_piau = get_tai_gi_by_han_ji(jin_kang_piau_im, han_ji) + tai_gi_im_piau = get_tai_gi_by_han_ji(jin_kang_piau_im_sheet, han_ji) found = True if tai_gi_im_piau else False # 若【破音字庫】有此漢字 if found: @@ -231,15 +299,18 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', ue_im_lui_piat=" tiau_ho ) han_ji_u_piau_im = True - sheet.range((row, col)).font.color = (255, 0, 0) # 將文字顏色設為【紅色】 - sheet.range((row, col)).color = (255, 255, 0) # 將底色設為【黄色】 print(f"漢字:【{han_ji}】之注音【{tai_gi_im_piau}】取自【人工注音字典】。") # 若【人工標音字庫】無此漢字,則在資料庫中查找 else: result = han_ji_ca_piau_im(cursor=cursor, han_ji=han_ji, ue_im_lui_piat=ue_im_lui_piat) + # 若【漢字庫】查無此字,登錄至【缺字表】 if not result: + maintain_han_ji_koo(sheet=khuat_ji_piau_sheet, + han_ji=han_ji, + tai_gi='', + show_msg=False) msg = f"【{han_ji}】查無此字!" else: # 依【漢字庫】查找結果,輸出【台語音標】和【漢字標音】 @@ -258,6 +329,9 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', ue_im_lui_piat=" show_msg=False) sheet.range((row - 1, col)).value = tai_gi_im_piau sheet.range((row + 1, col)).value = han_ji_piau_im + if manual_input: + sheet.range((row, col)).font.color = (255, 0, 0) # 將文字顏色設為【紅色】 + sheet.range((row, col)).color = (255, 255, 0) # 將底色設為【黄色】 msg = f"{han_ji}: [{tai_gi_im_piau}] /【{han_ji_piau_im}】" # 顯示處理進度 @@ -274,52 +348,53 @@ def ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', ue_im_lui_piat=" row += 4 #---------------------------------------------------------------------- - # 作業處理用的 row 迴圈與 col 迴圈己終結 + # 作業結束前處理 #---------------------------------------------------------------------- # 關閉資料庫連線 conn.close() - - # 作業結束前處理 - wb.save() print("已完成【台語音標】和【漢字標音】標注工作。") return EXIT_CODE_SUCCESS def process(wb): - # ------------------------------------------------------------------------------ - # 指定【作業工作表】為【漢字注音】工作表 - # ------------------------------------------------------------------------------ - sheet = wb.sheets["漢字注音"] # 選擇工作表 - sheet.activate() # 將「漢字注音」工作表設為作用中工作表 + # 動態載入查找函數 + module_name='mod_河洛話' + function_name='han_ji_ca_piau_im' + + # --------------------------------------------------------------------- + # 連上資料庫 + # --------------------------------------------------------------------- + han_ji_khoo_field = '漢字庫' + han_ji_khoo_name = get_value_by_name(wb=wb, name=han_ji_khoo_field) # 取得【漢字庫】名稱:河洛話、廣韻 + ue_im_lui_piat = get_value_by_name(wb, '語音類型') # 取得【語音類型】,判別使用【白話音】或【文讀音】何者。 + db_name = 'Ho_Lok_Ue.db' if han_ji_khoo_name == '河洛話' else 'Kong_Un.db' # ------------------------------------------------------------------------------ # 為漢字查找讀音,漢字上方填:【台語音標】;漢字下方填使用者指定之【漢字標音】 # ------------------------------------------------------------------------------ - type = get_value_by_name(wb, '語音類型') # 取得【語音類型】,判別使用【白話音】或【文讀音】何者。 - han_ji_khoo = get_value_by_name(wb, '漢字庫') - if han_ji_khoo == "河洛話" and type == "白話音": + if han_ji_khoo_name == "河洛話" and ue_im_lui_piat == "白話音": ca_han_ji_thak_im( wb=wb, sheet_name="漢字注音", cell="V3", - ue_im_lui_piat=type, - han_ji_khoo="河洛話", - db_name="Ho_Lok_Ue.db", - module_name="mod_河洛話", - function_name="han_ji_ca_piau_im", + ue_im_lui_piat=ue_im_lui_piat, # "白話音" + han_ji_khoo=han_ji_khoo_name, # "河洛話", + db_name=db_name, # "Ho_Lok_Ue.db", + module_name=module_name, # "mod_河洛話", + function_name=function_name # "han_ji_ca_piau_im", ) - elif han_ji_khoo == "河洛話" and type == "文讀音": + elif han_ji_khoo_name == "河洛話" and ue_im_lui_piat == "文讀音": ca_han_ji_thak_im( wb=wb, sheet_name="漢字注音", cell="V3", - ue_im_lui_piat=type, - han_ji_khoo="河洛話", - db_name="Ho_Lok_Ue.db", - module_name="mod_河洛話", - function_name="han_ji_ca_piau_im", + ue_im_lui_piat=ue_im_lui_piat, # "文讀音" + han_ji_khoo=han_ji_khoo_name, # "河洛話", + db_name=db_name, # "Ho_Lok_Ue.db", + module_name=module_name, # "mod_河洛話", + function_name=function_name # "han_ji_ca_piau_im", ) - elif han_ji_khoo == "廣韻": + elif han_ji_khoo_name == "廣韻": ca_han_ji_thak_im( wb=wb, sheet_name="漢字注音", diff --git "a/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263_R1.py" "b/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263_R1.py" deleted file mode 100644 index f24b945..0000000 --- "a/a702_\346\237\245\346\211\276\345\217\212\345\241\253\345\205\245\346\274\242\345\255\227\346\250\231\351\237\263_R1.py" +++ /dev/null @@ -1,176 +0,0 @@ -# ========================================================================= -# 載入程式所需套件/模組/函式庫 -# ========================================================================= -import logging -import os -import sys -from pathlib import Path - -# 載入第三方套件 -import xlwings as xw -from dotenv import load_dotenv - -# 載入自訂模組 -from mod_file_access import get_han_ji_khoo, get_sound_type, save_as_new_file -from p702_Ca_Han_Ji_Thak_Im import ca_han_ji_thak_im - -# ========================================================================= -# 載入環境變數 -# ========================================================================= -load_dotenv() - -# 預設檔案名稱從環境變數讀取 -DB_HO_LOK_UE = os.getenv('DB_HO_LOK_UE', 'Ho_Lok_Ue.db') -DB_KONG_UN = os.getenv('DB_KONG_UN', 'Kong_Un.db') - -# ========================================================================= -# 設定日誌 -# ========================================================================= -logging.basicConfig( - filename='process_log.txt', - level=logging.INFO, - format='%(asctime)s - %(levelname)s - %(message)s' -) - -def logging_process_step(msg): - print(msg) - logging.info(msg) - -# ========================================================================= -# 常數定義 -# ========================================================================= -# 定義 Exit Code -EXIT_CODE_SUCCESS = 0 # 成功 -EXIT_CODE_NO_FILE = 1 # 無法找到檔案 -EXIT_CODE_INVALID_INPUT = 2 # 輸入錯誤 -EXIT_CODE_PROCESS_FAILURE = 3 # 過程失敗 -EXIT_CODE_UNKNOWN_ERROR = 99 # 未知錯誤 - -# ========================================================================= -# 作業程序 -# ========================================================================= -def process(wb): - # ------------------------------------------------------------------------------ - # 指定【作業中工作表】 - # ------------------------------------------------------------------------------ - sheet = wb.sheets["漢字注音"] # 選擇工作表 - sheet.activate() # 將「漢字注音」工作表設為作用中工作表 - sheet.range("A1").select() # 將 A1 儲存格設為作用儲存格 - - # ------------------------------------------------------------------------------ - # 為漢字查找讀音,漢字上方填:【台語音標】;漢字下方填使用者指定之【漢字標音】 - # ------------------------------------------------------------------------------ - type = get_sound_type(wb) # 取得【語音類型】,判別使用【白話音】或【文讀音】何者。 - han_ji_khoo = get_han_ji_khoo(wb) - if han_ji_khoo == "河洛話" and type == "白話音": - ca_han_ji_thak_im( - wb=wb, - sheet_name="漢字注音", - cell="V3", - ue_im_lui_piat=type, - han_ji_khoo="河洛話", - db_name="Ho_Lok_Ue.db", - module_name="mod_河洛話", - function_name="han_ji_ca_piau_im", - ) - elif han_ji_khoo == "河洛話" and type == "文讀音": - ca_han_ji_thak_im( - wb=wb, - sheet_name="漢字注音", - cell="V3", - ue_im_lui_piat=type, - han_ji_khoo="河洛話", - db_name="Ho_Lok_Ue.db", - module_name="mod_河洛話", - function_name="han_ji_ca_piau_im", - ) - elif han_ji_khoo == "廣韻": - ca_han_ji_thak_im( - wb=wb, - sheet_name="漢字注音", - cell="V3", - ue_im_lui_piat="文讀音", - han_ji_khoo="廣韻", - db_name="Kong_Un.db", - module_name="mod_廣韻", - function_name="han_ji_ca_piau_im", - ) - else: - msg = "無法執行漢字標音作業,請確認【env】工作表【語音類型】及【漢字庫】欄位的設定是否正確!" - print(msg) - logging.error(msg) - return EXIT_CODE_INVALID_INPUT - - #-------------------------------------------------------------------------- - # 作業結尾處理 - #-------------------------------------------------------------------------- - save_as_new_file(wb=wb) - logging.info("己存檔至路徑:{file_path}") - return EXIT_CODE_SUCCESS - - -# ============================================================================= -# 程式主流程 -# ============================================================================= -def main(): - # ========================================================================= - # 開始作業 - # ========================================================================= - logging.info("作業開始") - - # ========================================================================= - # (1) 取得專案根目錄。 - # ========================================================================= - current_file_path = Path(__file__).resolve() - project_root = current_file_path.parent - logging_process_step(f"專案根目錄為: {project_root}") - - # ========================================================================= - # (2) 設定【作用中活頁簿】:偵測及獲取 Excel 已開啟之活頁簿檔案。 - # ========================================================================= - wb = None - # 取得【作用中活頁簿】 - try: - wb = xw.apps.active.books.active # 取得 Excel 作用中的活頁簿檔案 - except Exception as e: - print(f"發生錯誤: {e}") - logging.error(f"無法找到作用中的 Excel 工作簿: {e}", exc_info=True) - return EXIT_CODE_NO_FILE - - # 若無法取得【作用中活頁簿】,則因無法繼續作業,故返回【作業異常終止代碼】結束。 - if not wb: - return EXIT_CODE_NO_FILE - - # ========================================================================= - # (3) 執行【處理作業】 - # ========================================================================= - try: - result_code = process(wb) - if result_code != EXIT_CODE_SUCCESS: - logging_process_step("作業異常終止!") - return result_code - - except Exception as e: - print(f"作業過程發生未知的異常錯誤: {e}") - logging.error(f"作業過程發生未知的異常錯誤: {e}", exc_info=True) - return EXIT_CODE_UNKNOWN_ERROR - - finally: - if wb: - # xw.apps.active.quit() # 確保 Excel 被釋放資源,避免開啟殘留 - logging.info("a702_查找及填入漢字標音.py 程式已執行完畢!") - - # ========================================================================= - # 結束作業 - # ========================================================================= - logging.info("作業完成!") - return EXIT_CODE_SUCCESS - - -if __name__ == "__main__": - exit_code = main() - if exit_code == EXIT_CODE_SUCCESS: - print("程式正常完成!") - else: - print(f"程式異常終止,錯誤代碼為: {exit_code}") - sys.exit(exit_code) diff --git "a/a706_\346\211\213\345\213\225\346\233\264\346\255\243\346\274\242\345\255\227\346\250\231\351\237\263.py" "b/a706_\346\211\213\345\213\225\346\233\264\346\255\243\346\274\242\345\255\227\346\250\231\351\237\263.py" index abdd62b..1e8d297 100644 --- "a/a706_\346\211\213\345\213\225\346\233\264\346\255\243\346\274\242\345\255\227\346\250\231\351\237\263.py" +++ "b/a706_\346\211\213\345\213\225\346\233\264\346\255\243\346\274\242\345\255\227\346\250\231\351\237\263.py" @@ -3,8 +3,10 @@ # ========================================================================= import logging import os +import sqlite3 import sys from pathlib import Path +from typing import Callable # 載入第三方套件 import xlwings as xw @@ -14,14 +16,15 @@ from a701_作業中活頁檔填入漢字 import process as fill_hanji_in_cells # 載入自訂模組/函式 -from mod_excel_access import ( - get_han_ji_khoo, - get_total_rows_in_sheet, - maintain_han_ji_koo, -) -from mod_file_access import save_as_new_file +# from p709_reset_han_ji_cells import reset_han_ji_cells +from a702_查找及填入漢字標音 import reset_han_ji_cells + +# 載入自訂模組/函式 +from mod_excel_access import get_han_ji_khoo, get_value_by_name, maintain_han_ji_koo +from mod_file_access import load_module_function, save_as_new_file +from mod_標音 import PiauIm # 漢字標音物件 from mod_標音 import is_punctuation # 是否為標點符號 -from p709_reset_han_ji_cells import reset_han_ji_cells +from mod_標音 import tlpa_tng_han_ji_piau_im # 台語音標轉台語音標 # ========================================================================= # 載入環境變數 @@ -59,43 +62,47 @@ def logging_process_step(msg): # ========================================================================= # 本程式主要處理作業程序 # ========================================================================= -def update_han_ji_piau_im(wb, han_ji_khoo_sheet_name='漢字庫', jin_kang_piau_im_sheet_name='人工標音字庫'): +def update_han_ji_piau_im(wb): """ - 更新【漢字注音】表中【台語音標】儲存格的內容,依據【漢字庫】中的【校正】欄位進行更新。 - wb: Excel 活頁簿物件 - han_ji_koo_sheet_name: 【漢字庫】工作表名稱 - han_ji_zhu_yin_sheet_name: 【漢字注音】工作表名稱 + 更新【漢字注音】表中【台語音標】儲存格的內容,依據【標音字庫】中的【校正音標】欄位進行更新,並將【校正音標】覆蓋至原【台語音標】。 """ + # 建置 PiauIm 物件,供作漢字拼音轉換作業 + han_ji_khoo_field = '漢字庫' + han_ji_khoo_name = get_value_by_name(wb=wb, name=han_ji_khoo_field) # 取得【漢字庫】名稱:河洛話、廣韻 + piau_im = PiauIm(han_ji_khoo=han_ji_khoo_name) # 指定漢字自動查找使用的【漢字庫】 + ue_im_lui_piat = get_value_by_name(wb=wb, name='語音類型') + piau_im_huat = get_value_by_name(wb=wb, name='標音方法') # 指定【台語音標】轉換成【漢字標音】的方法 + # 取得工作表 han_ji_piau_im_sheet = wb.sheets['漢字注音'] - han_ji_khoo_sheet = wb.sheets[han_ji_khoo_sheet_name] - jin_kang_piau_im_sheet = wb.sheets[jin_kang_piau_im_sheet_name] + piau_im_sheet_name = '標音字庫' + piau_im_ji_khoo_sheet = get_han_ji_khoo(wb=wb, sheet_name=piau_im_sheet_name) - # 取得【漢字庫】表格範圍的所有資料 - data = han_ji_khoo_sheet.range("A2").expand("table").value + # 取得【標音字庫】表格範圍的所有資料 + data = piau_im_ji_khoo_sheet.range("A2").expand("table").value if data is None: - print("【漢字庫】工作表無資料") + print("【標音字庫】工作表無資料") return EXIT_CODE_INVALID_INPUT # 確保資料為 2D 列表 if not isinstance(data[0], list): data = [data] - # 將資料轉為字典格式,key: 漢字, value: (台語音標, 校正, 次數) + # 將資料轉為字典格式,key: 漢字, value: (台語音標, 校正音標, 次數) han_ji_dict = {} - for row in data: + for i, row in enumerate(data, start=2): han_ji = row[0] or "" tai_gi_im_piau = row[1] or "" total_count = int(row[2]) if len(row) > 2 and isinstance(row[2], (int, float)) else 0 corrected_tai_gi = row[3] if len(row) > 3 else "" # 若無 D 欄資料則設為空字串 - if corrected_tai_gi and (corrected_tai_gi != tai_gi_im_piau): - han_ji_dict[han_ji] = (tai_gi_im_piau, corrected_tai_gi, total_count) + if corrected_tai_gi and corrected_tai_gi != tai_gi_im_piau: + han_ji_dict[han_ji] = (tai_gi_im_piau, corrected_tai_gi, total_count, i) # i 為資料列索引 # 若無需更新的資料,結束函數 if not han_ji_dict: - print("【漢字庫】工作表中,【校正音標】欄,均未填入需更新之台語音標!") + print("【標音字庫】工作表中,【校正音標】欄,均未填入需更新之台語音標!") return EXIT_CODE_SUCCESS # 逐列處理【漢字注音】表 @@ -114,40 +121,55 @@ def update_han_ji_piau_im(wb, han_ji_khoo_sheet_name='漢字庫', jin_kang_piau_ han_ji = han_ji_cell.value or "" if han_ji in han_ji_dict: - _, corrected_tai_gi, total_count = han_ji_dict[han_ji] + original_tai_gi, corrected_tai_gi, total_count, row_index_in_ji_khoo = han_ji_dict[han_ji] tai_gi_cell = han_ji_piau_im_sheet.range((row - 1, col)) - original_tai_gi = tai_gi_cell.value or "" + original_tai_gi_in_sheet = tai_gi_cell.value or "" jin_kang_piau_im_cell = han_ji_piau_im_sheet.range((row + 2, col)) jin_kang_piau_im = jin_kang_piau_im_cell.value or "" + han_ji_piau_im_cell = han_ji_piau_im_sheet.range((row + 1, col)) # 更新多次,直到總數用完 - if corrected_tai_gi != original_tai_gi and total_count > 0: + if corrected_tai_gi != original_tai_gi_in_sheet and total_count > 0: if jin_kang_piau_im: # 若【人工標音】已有標音,則不進行更新 msg = f"({row}, {xw.utils.col_name(col)}) = {han_ji},已有人工標音【{jin_kang_piau_im}】,故無更新" else: - tai_gi_cell.value = corrected_tai_gi # 更新儲存格 + tai_gi_cell.value = corrected_tai_gi # 更新【台語音標】儲存格 han_ji_cell.color = (255, 255, 0) # 將底色設為【黄色】 han_ji_cell.font.color = (255, 0, 0) # 將文字顏色設為【紅色】 - msg = f"({row}, {xw.utils.col_name(col)}) = {han_ji},台語音標由【{original_tai_gi}】改為【{corrected_tai_gi}】" + + tai_gi_im_piau = corrected_tai_gi + han_ji_piau_im = tlpa_tng_han_ji_piau_im( + piau_im=piau_im, + piau_im_huat=piau_im_huat, + tai_gi_im_piau=tai_gi_im_piau + ) + han_ji_piau_im_cell.value = han_ji_piau_im # 更新【漢字標音】儲存格 + + # 更新【標音字庫】中原【台語音標】欄位內容 + piau_im_ji_khoo_sheet.range(f"B{row_index_in_ji_khoo}").value = corrected_tai_gi + msg = f"({row}, {xw.utils.col_name(col)}) = {han_ji},台語音標由【{original_tai_gi_in_sheet}】改為【{corrected_tai_gi}】/【{han_ji_piau_im}】" print(msg) total_count -= 1 # 減少剩餘更新次數 - # 更新完畢後,減少【漢字庫】的總數 - han_ji_khoo_sheet.range(f"C{row + 1}").value = total_count + # 更新完畢後,減少【標音字庫】的總數 + piau_im_ji_khoo_sheet.range(f"C{row_index_in_ji_khoo}").value = total_count if total_count == 0: print(f"漢字【{han_ji}】的更新次數已用完") print("【漢字注音】表的台語音標更新作業已完成") # 作業結束前處理 - logging_process_step(f"完成【作業程序】:更新漢字標音...") + logging_process_step(f"完成【作業程序】:更新漢字標音並同步【標音字庫】內容...") return EXIT_CODE_SUCCESS def process(wb): - return_code = update_han_ji_piau_im(wb) + # --------------------------------------------------------------------- + # 依【標音字庫】的【校正音標】,更新【漢字注音】表中的【台語音標】 + # --------------------------------------------------------------------- + return_code = update_han_ji_piau_im(wb=wb) if return_code != EXIT_CODE_SUCCESS: logging_process_step("處理作業失敗,過程中出錯!") return return_code diff --git "a/bu-a720_\345\276\205\346\263\250\351\237\263\346\274\242\345\255\227\345\241\253\345\205\245\346\250\231\351\237\263\347\224\250\346\226\271\346\240\274.py" "b/bu-a720_\345\276\205\346\263\250\351\237\263\346\274\242\345\255\227\345\241\253\345\205\245\346\250\231\351\237\263\347\224\250\346\226\271\346\240\274.py" deleted file mode 100644 index 3ae29d3..0000000 --- "a/bu-a720_\345\276\205\346\263\250\351\237\263\346\274\242\345\255\227\345\241\253\345\205\245\346\250\231\351\237\263\347\224\250\346\226\271\346\240\274.py" +++ /dev/null @@ -1,86 +0,0 @@ -# 填漢字等標音:將整段的文字拆解,個別填入儲存格,以便後續人工手動填入台語音標、注音符號。 -import getopt -import sys - -import xlwings as xw - -import settings -from p701_Clear_Cells import clear_hanji_in_cells -from p710_thiam_han_ji import fill_hanji_in_cells - - -def get_input_and_output_options(argv): - arg_input = "" - arg_output = "" - arg_user = "" - arg_help = "{0} -i -u -o ".format(argv[0]) - - try: - opts, args = getopt.getopt( # pyright: ignore - argv[1:], "hi:u:o:", ["help", "input=", "user=", "output="] - ) - except Exception as e: - print(e) - print(arg_help) - sys.exit(2) - - for opt, arg in opts: - if opt in ("-h", "--help"): - print(arg_help) # print the help message - sys.exit(2) - elif opt in ("-i", "--input"): - arg_input = arg - elif opt in ("-u", "--user"): - arg_user = arg - elif opt in ("-o", "--output"): - arg_output = arg - - print("input:", arg_input) - print("user:", arg_user) - print("output:", arg_output) - - return { - "input": arg_input, - "user": arg_user, - "output": arg_output, - } - - -if __name__ == "__main__": - # ========================================================================= - # (1) 取得需要注音的「檔案名稱」及其「目錄路徑」。 - # ========================================================================= - # 取得 Input 檔案名稱 - file_path = settings.get_tai_gi_zu_im_bun_path() - if not file_path: - print("未設定 .env 檔案") - # sys.exit(2) - opts = get_input_and_output_options(sys.argv) - if opts["input"] != "": - CONVERT_FILE_NAME = opts["input"] - else: - CONVERT_FILE_NAME = "Tai_Gi_Zu_Im_Bun.xlsx" - else: - CONVERT_FILE_NAME = file_path - print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") - - # 打開 Excel 檔案 - wb = xw.Book(CONVERT_FILE_NAME) - - # 顯示「已輸入之拼音字母及注音符號」 - named_range = wb.names['顯示注音輸入'] # 選擇名為 "顯示注音輸入" 的命名範圍# 選擇名為 "顯示注音輸入" 的命名範圍 - named_range.refers_to_range.value = True - - # ========================================================================= - # (2) 將漢字填入 - # - 上方:台語音標 - # - 下方:台語注音符號 - # ========================================================================= - # 選擇工作表 - sheet = wb.sheets['漢字注音'] - - # 清除 C3:R166 範圍的內容 - sheet.range('D3:R166').clear_contents() - - # 將漢字逐個填入各儲存格 - fill_hanji_in_cells(wb) diff --git "a/bu-a730_\345\260\207\346\274\242\345\255\227\346\263\250\351\237\263\345\241\253\345\205\245.py" "b/bu-a730_\345\260\207\346\274\242\345\255\227\346\263\250\351\237\263\345\241\253\345\205\245.py" deleted file mode 100644 index 52a90e8..0000000 --- "a/bu-a730_\345\260\207\346\274\242\345\255\227\346\263\250\351\237\263\345\241\253\345\205\245.py" +++ /dev/null @@ -1,91 +0,0 @@ -import getopt -import sys - -import xlwings as xw - -import settings -from p720_Thiam_Zu_Im import thiam_zu_im - - -def get_input_and_output_options(argv): - arg_input = "" - arg_output = "" - arg_user = "" - arg_help = "{0} -i -u -o ".format(argv[0]) - - try: - opts, args = getopt.getopt( # pyright: ignore - argv[1:], "hi:u:o:", ["help", "input=", "user=", "output="] - ) - except Exception as e: - print(e) - print(arg_help) - sys.exit(2) - - for opt, arg in opts: - if opt in ("-h", "--help"): - print(arg_help) # print the help message - sys.exit(2) - elif opt in ("-i", "--input"): - arg_input = arg - elif opt in ("-u", "--user"): - arg_user = arg - elif opt in ("-o", "--output"): - arg_output = arg - - print("input:", arg_input) - print("user:", arg_user) - print("output:", arg_output) - - return { - "input": arg_input, - "user": arg_user, - "output": arg_output, - } - - -if __name__ == "__main__": - # ========================================================================= - # (1) 取得需要注音的「檔案名稱」及其「目錄路徑」。 - # ========================================================================= - # 取得 Input 檔案名稱 - file_path = settings.get_tai_gi_zu_im_bun_path() - if not file_path: - print("未設定 .env 檔案") - # sys.exit(2) - opts = get_input_and_output_options(sys.argv) - if opts["input"] != "": - CONVERT_FILE_NAME = opts["input"] - else: - CONVERT_FILE_NAME = "Tai_Gi_Zu_Im_Bun.xlsx" - else: - CONVERT_FILE_NAME = file_path - print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") - - # 打開 Excel 檔案 - wb = xw.Book(CONVERT_FILE_NAME) - - # ========================================================================= - # (2) 分析已輸入的【台語音標】及【台語注音符號】,將之各別填入漢字之上、下方。 - # - 上方:台語音標 - # - 下方:台語注音符號 - # ========================================================================= - thiam_zu_im(wb, '漢字注音', 'V3') - - # ========================================================================= - # (3) 依據《文章標題》另存新檔。 - # ========================================================================= - # wb = xw.Book(CONVERT_FILE_NAME) - # setting_sheet = wb.sheets["env"] - # new_file_name = str( - # setting_sheet.range("C4").value - # ).strip() - # new_file_path = os.path.join( - # ".\\output", - # f"【河洛話注音】{new_file_name}" + ".xlsx") - - # # 儲存新建立的工作簿 - # wb.save(new_file_path) - - # 保存 Excel 檔案 - # wb.close() diff --git a/fun_ha_ji_tsa_un_bu.py b/fun_ha_ji_tsa_un_bu.py deleted file mode 100644 index 3dc3523..0000000 --- a/fun_ha_ji_tsa_un_bu.py +++ /dev/null @@ -1,40 +0,0 @@ -import xlwings as xw - -def ha_ji_tsa_un_bu(ha_ji): - try: - # 使用 xlwings 打開 Excel 檔案 - file_path = r'.\\tools\\反切下字與韻母對映表.xlsx' - wb = xw.Book(file_path) - sheet = wb.sheets['反切下字表'] - - # 查找 ha_ji 在指定範圍 (J2:J187) 的位置 - for row in range(2, 188): # 資料從第2列開始,到第187列 - cell_value = sheet.range(f'J{row}').value - if cell_value: - words = cell_value.split() # 按空格拆分儲存格的值 - if ha_ji in words: - # 如果找到了 ha_ji,則記錄下其相對映之 "列號",並從相關欄位獲取資料 - data = { - "id": row - 1, # 第一行為標題行,故實際列號需要減1 - "liap": sheet.range(f'B{row}').value, # 攝 - "un_he": sheet.range(f'C{row}').value, # 韻系 - "si_siann": sheet.range(f'D{row}').value, # 四聲 (平上去入) - "ting_de": sheet.range(f'E{row}').value, # 等第 - "khai_hap": sheet.range(f'F{row}').value, # 開合 - "un_bu": sheet.range(f'G{row}').value, # 韻母 - "tai_lo": sheet.range(f'H{row}').value, # 臺羅拼音 - "IPA": sheet.range(f'I{row}').value, # 國際音標 - } - wb.close() # 處理完成後關閉工作簿 - return data - wb.close() # 如果沒找到,也關閉工作簿 - return None # 如果在範圍內沒有找到 ha_ji,返回 None - except Exception as e: - print(f"發生錯誤:{e}") - return None - - -# 測試函數 -ha_ji = "荅" # 假設的反切上字 -result = ha_ji_tsa_un_bu(ha_ji) -print(result) \ No newline at end of file diff --git a/fun_siong_ji_tsa_siann_bu.py b/fun_siong_ji_tsa_siann_bu.py deleted file mode 100644 index 2ada062..0000000 --- a/fun_siong_ji_tsa_siann_bu.py +++ /dev/null @@ -1,35 +0,0 @@ -import xlwings as xw - -def siong_ji_tsa_siann_bu(siong_ji): - try: - # 使用 xlwings 打開 Excel 檔案 - file_path = r'.\\tools\\反切上字與聲母對映表.xlsx' - wb = xw.Book(file_path) - sheet = wb.sheets['反切上字表'] # 假設工作表的名稱為 "反切上字" - - # 查找 siong_ji 在 "反切上字" 欄 (G2:G39) 的位置 - for row in range(2, 40): # 假設資料從第2行開始,到第39行 - cell_value = sheet.range(f'G{row}').value - if cell_value: - words = cell_value.split() # 按空格拆分儲存格的值 - if siong_ji in words: - # 如果找到了 siong_ji,則記錄下其相對映之 "列號",並從相關欄位獲取資料 - data = { - "id": row - 1, # 第一行為標題行,故實際列號需要減1 - "lui": sheet.range(f'B{row}').value, - "siann_bu": sheet.range(f'C{row}').value, - "tai_lo": sheet.range(f'D{row}').value, - "IPA": sheet.range(f'E{row}').value, - } - wb.close() # 處理完成後關閉工作簿 - return data - wb.close() # 如果沒找到,也關閉工作簿 - return None # 如果在範圍內沒有找到 siong_ji,返回 None - except Exception as e: - print(f"發生錯誤:{e}") - return None - -# 測試函數 -siong_ji = "普" # 假設的反切上字 -result = siong_ji_tsa_siann_bu(siong_ji) -print(result) diff --git a/mod_excel_access.py b/mod_excel_access.py index a10c2ae..77c30fa 100644 --- a/mod_excel_access.py +++ b/mod_excel_access.py @@ -56,6 +56,24 @@ def logging_process_step(msg): # ========================================================================= # 程式用函式 # ========================================================================= +def delete_sheet_by_name(wb, sheet_name: str, show_msg: bool=False): + """ + 刪除指定名稱的工作表 + wb: Excel 活頁簿物件 + sheet_name: 要刪除的工作表名稱 + """ + try: + # 檢查工作表是否存在 + if sheet_name in [sheet.name for sheet in wb.sheets]: + sheet = wb.sheets[sheet_name] + sheet.delete() # 刪除工作表 + if show_msg: print(f"已成功刪除工作表:{sheet_name}") + else: + if show_msg: print(f"無法刪除,工作表 {sheet_name} 不存在") + except Exception as e: + if show_msg: print(f"刪除工作表時發生錯誤:{e}") + + def get_value_by_name(wb, name): try: if name in wb.names: @@ -66,7 +84,7 @@ def get_value_by_name(wb, name): value = None return value -def get_han_ji_khoo(wb, sheet_name="漢字庫"): +def get_han_ji_khoo(wb, sheet_name="標音字庫"): """ 從 Excel 工作表中取得漢字庫 wb: Excel 活頁簿物件 diff --git "a/output7/\343\200\220\346\262\263\346\264\233\347\231\275\350\251\261\346\263\250\351\237\263-\351\233\205\344\277\227\351\200\232\343\200\221\343\200\212TestCase\343\200\213.xlsx" "b/output7/\343\200\220\346\262\263\346\264\233\347\231\275\350\251\261\346\263\250\351\237\263-\351\233\205\344\277\227\351\200\232\343\200\221\343\200\212TestCase\343\200\213.xlsx" index 7ff760e..715fb85 100644 Binary files "a/output7/\343\200\220\346\262\263\346\264\233\347\231\275\350\251\261\346\263\250\351\237\263-\351\233\205\344\277\227\351\200\232\343\200\221\343\200\212TestCase\343\200\213.xlsx" and "b/output7/\343\200\220\346\262\263\346\264\233\347\231\275\350\251\261\346\263\250\351\237\263-\351\233\205\344\277\227\351\200\232\343\200\221\343\200\212TestCase\343\200\213.xlsx" differ diff --git a/process_log.txt b/process_log.txt index 1d849a8..292d92b 100644 --- a/process_log.txt +++ b/process_log.txt @@ -1383,3 +1383,224 @@ Exception: All elements of a 2d list or tuple must be of the same length 2025-01-13 14:13:49,397 - INFO - 完成【處理作業】... 2025-01-13 14:13:49,468 - INFO - 釋放 Excel 資源,處理完成。 2025-01-13 14:13:49,468 - INFO - 作業成功完成! +2025-01-13 14:20:57,325 - INFO - 作業開始 +2025-01-13 14:20:57,326 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 14:21:29,876 - ERROR - 作業過程發生未知的異常錯誤: All elements of a 2d list or tuple must be of the same length +Traceback (most recent call last): + File "a702_查找及填入漢字標音.py", line 383, in main + result_code = process(wb) + File "a702_查找及填入漢字標音.py", line 301, in process + ca_han_ji_thak_im( + ~~~~~~~~~~~~~~~~~^ + wb=wb, + ^^^^^^ + ...<6 lines>... + function_name="han_ji_ca_piau_im", + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + ) + ^ + File "a702_查找及填入漢字標音.py", line 255, in ca_han_ji_thak_im + maintain_han_ji_koo(sheet=han_ji_koo_sheet, + ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ + han_ji=han_ji, + ^^^^^^^^^^^^^^ + tai_gi=tai_gi_im_piau, + ^^^^^^^^^^^^^^^^^^^^^^ + show_msg=False) + ^^^^^^^^^^^^^^^ + File "c:\work\Piau-Im\mod_excel_access.py", line 125, in maintain_han_ji_koo + sheet.range("A2").value = records # 寫入更新後的資料 + ^^^^^^^^^^^^^^^^^^^^^^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\main.py", line 2482, in value + conversion.write(data, self, self._options) + ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\conversion\__init__.py", line 94, in write + raise Exception( + "All elements of a 2d list or tuple must be of the same length" + ) +Exception: All elements of a 2d list or tuple must be of the same length +2025-01-13 14:21:29,900 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 14:22:50,766 - INFO - 作業開始 +2025-01-13 14:22:50,768 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 14:23:39,826 - INFO - 己存檔至路徑:{file_path} +2025-01-13 14:23:39,826 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 14:23:39,826 - INFO - 作業完成! +2025-01-13 15:24:33,801 - INFO - 作業開始 +2025-01-13 15:24:33,803 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 15:25:23,643 - INFO - 己存檔至路徑:{file_path} +2025-01-13 15:25:23,643 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 15:25:23,643 - INFO - 作業完成! +2025-01-13 15:27:24,595 - INFO - 作業開始 +2025-01-13 15:27:24,596 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 15:28:14,103 - INFO - 己存檔至路徑:{file_path} +2025-01-13 15:28:14,104 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 15:28:14,104 - INFO - 作業完成! +2025-01-13 15:48:29,297 - INFO - 作業開始 +2025-01-13 15:48:29,298 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 15:49:19,690 - INFO - 己存檔至路徑:{file_path} +2025-01-13 15:49:19,690 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 15:49:19,690 - INFO - 作業完成! +2025-01-13 16:01:45,921 - INFO - 作業開始 +2025-01-13 16:01:45,922 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:02:36,713 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:02:36,714 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:02:36,714 - INFO - 作業完成! +2025-01-13 16:05:06,068 - INFO - 作業開始 +2025-01-13 16:05:06,069 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:06:14,362 - ERROR - 作業過程發生未知的異常錯誤: (-2147352567, '發生例外狀況。', (0, 'Microsoft Excel', 'Class Range 的 Select 方法失敗', 'xlmain11.chm', 0, -2146827284), None) +Traceback (most recent call last): + File "a702_查找及填入漢字標音.py", line 391, in main + result_code = process(wb) + File "a702_查找及填入漢字標音.py", line 309, in process + ca_han_ji_thak_im( + ~~~~~~~~~~~~~~~~~^ + wb=wb, + ^^^^^^ + ...<6 lines>... + function_name="han_ji_ca_piau_im", + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + ) + ^ + File "a702_查找及填入漢字標音.py", line 154, in ca_han_ji_thak_im + sheet.range((row, 1)).select() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\main.py", line 2815, in select + self.impl.select() + ~~~~~~~~~~~~~~~~^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\_xlwindows.py", line 1500, in select + return self.xl.Select() + ~~~~~~~~~~~~~~^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\_xlwindows.py", line 122, in __call__ + v = self.__method(*args, **kwargs) + File ">", line 2, in Select + File "c:\work\Piau-Im\.venv\Lib\site-packages\win32com\client\dynamic.py", line 355, in _ApplyTypes_ + result = self._oleobj_.InvokeTypes( + *(dispid, LCID, wFlags, retType, argTypes) + args + ) +pywintypes.com_error: (-2147352567, '發生例外狀況。', (0, 'Microsoft Excel', 'Class Range 的 Select 方法失敗', 'xlmain11.chm', 0, -2146827284), None) +2025-01-13 16:06:14,369 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:08:36,117 - INFO - 作業開始 +2025-01-13 16:08:36,118 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:09:26,548 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:09:26,548 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:09:26,548 - INFO - 作業完成! +2025-01-13 16:22:44,428 - INFO - 作業開始 +2025-01-13 16:22:44,430 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:23:38,486 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:23:38,486 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:23:38,486 - INFO - 作業完成! +2025-01-13 16:25:17,744 - INFO - 作業開始 +2025-01-13 16:25:17,745 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:26:12,009 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:26:12,009 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:26:12,009 - INFO - 作業完成! +2025-01-13 16:27:07,971 - INFO - 作業開始 +2025-01-13 16:27:07,972 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:28:00,615 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:28:00,615 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:28:00,615 - INFO - 作業完成! +2025-01-13 16:37:01,720 - INFO - 作業開始 +2025-01-13 16:37:01,721 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:37:10,961 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:37:10,961 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:37:10,961 - INFO - 作業完成! +2025-01-13 16:38:34,701 - INFO - 作業開始 +2025-01-13 16:38:34,702 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:38:43,640 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:38:43,640 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:38:43,640 - INFO - 作業完成! +2025-01-13 16:39:32,976 - INFO - 作業開始 +2025-01-13 16:39:32,977 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:40:25,447 - INFO - 己存檔至路徑:{file_path} +2025-01-13 16:40:25,447 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 16:40:25,447 - INFO - 作業完成! +2025-01-13 16:55:04,247 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 16:55:04,267 - ERROR - 執行過程中發生未知錯誤: (-2147352567, '發生例外狀況。', (0, None, None, None, 0, -2147352565), None) +Traceback (most recent call last): + File "a706_手動更正漢字標音.py", line 198, in main + result_code = process(wb) + File "a706_手動更正漢字標音.py", line 157, in process + return_code = update_han_ji_piau_im(wb) + File "a706_手動更正漢字標音.py", line 74, in update_han_ji_piau_im + han_ji_khoo_sheet = wb.sheets[han_ji_khoo_sheet_name] + ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\main.py", line 89, in __getitem__ + return self(key) + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\main.py", line 5218, in __call__ + return Sheet(impl=self.impl(name_or_index)) + ~~~~~~~~~^^^^^^^^^^^^^^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\_xlwindows.py", line 943, in __call__ + return Sheet(xl=self.xl(name_or_index)) + ~~~~~~~^^^^^^^^^^^^^^^ + File "c:\work\Piau-Im\.venv\Lib\site-packages\xlwings\_xlwindows.py", line 236, in __call__ + v = self._inner(*args, **kwargs) + File "c:\work\Piau-Im\.venv\Lib\site-packages\win32com\client\dynamic.py", line 213, in __call__ + self._oleobj_.Invoke(*allArgs), self._olerepr_.defaultDispatchName, None + ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^ +pywintypes.com_error: (-2147352567, '發生例外狀況。', (0, None, None, None, 0, -2147352565), None) +2025-01-13 16:55:04,337 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:03:41,448 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:04:14,021 - INFO - 完成【作業程序】:更新漢字標音... +2025-01-13 17:04:14,021 - INFO - 完成【處理作業】... +2025-01-13 17:04:14,093 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:04:14,093 - INFO - 作業成功完成! +2025-01-13 17:38:12,132 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:38:24,208 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 17:38:32,786 - INFO - 完成【處理作業】... +2025-01-13 17:38:32,873 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:38:32,873 - INFO - 作業成功完成! +2025-01-13 17:39:53,580 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:40:06,203 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 17:40:06,203 - INFO - 完成【處理作業】... +2025-01-13 17:40:06,267 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:40:06,267 - INFO - 作業成功完成! +2025-01-13 17:40:37,701 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:40:49,702 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 17:40:49,702 - INFO - 完成【處理作業】... +2025-01-13 17:40:49,771 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:40:49,771 - INFO - 作業成功完成! +2025-01-13 17:41:47,291 - INFO - 作業開始 +2025-01-13 17:41:47,292 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:42:40,304 - INFO - 己存檔至路徑:{file_path} +2025-01-13 17:42:40,304 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 17:42:40,304 - INFO - 作業完成! +2025-01-13 17:43:16,699 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:49:10,630 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 17:49:10,630 - INFO - 完成【處理作業】... +2025-01-13 17:49:10,702 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:49:10,702 - INFO - 作業成功完成! +2025-01-13 17:49:47,360 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 17:49:59,850 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 17:49:59,850 - INFO - 完成【處理作業】... +2025-01-13 17:49:59,919 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 17:49:59,919 - INFO - 作業成功完成! +2025-01-13 19:15:50,215 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 19:17:03,238 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 19:17:03,238 - INFO - 完成【處理作業】... +2025-01-13 19:17:03,304 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 19:17:03,304 - INFO - 作業成功完成! +2025-01-13 19:20:46,362 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 19:20:58,877 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 19:20:58,878 - INFO - 完成【處理作業】... +2025-01-13 19:20:58,949 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 19:20:58,949 - INFO - 作業成功完成! +2025-01-13 20:12:17,982 - INFO - 作業開始 +2025-01-13 20:12:17,983 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 20:13:15,446 - INFO - 己存檔至路徑:{file_path} +2025-01-13 20:13:15,446 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 20:13:15,446 - INFO - 作業完成! +2025-01-13 20:13:24,315 - INFO - 作業開始 +2025-01-13 20:13:24,316 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 20:14:26,209 - INFO - 己存檔至路徑:{file_path} +2025-01-13 20:14:26,209 - INFO - a702_查找及填入漢字標音.py 程式已執行完畢! +2025-01-13 20:14:26,210 - INFO - 作業完成! +2025-01-13 20:15:54,117 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 20:16:06,915 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 20:16:06,915 - INFO - 完成【處理作業】... +2025-01-13 20:16:06,976 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 20:16:06,976 - INFO - 作業成功完成! +2025-01-13 20:17:54,816 - INFO - 專案根目錄為: C:\work\Piau-Im +2025-01-13 20:18:13,020 - INFO - 完成【作業程序】:更新漢字標音並同步【標音字庫】內容... +2025-01-13 20:18:13,020 - INFO - 完成【處理作業】... +2025-01-13 20:18:13,082 - INFO - 釋放 Excel 資源,處理完成。 +2025-01-13 20:18:13,083 - INFO - 作業成功完成!