diff --git a/.vscode/launch.json b/.vscode/launch.json index dab0965..72622e9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,16 @@ // 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { + "name": "a700_Iong_Excel_Piau_Zu_Im", + "type": "debugpy", + "request": "launch", + "program": "a700_Iong_Excel_Piau_Zu_Im.py", + "console": "integratedTerminal", + "args": [ + "a700_Iong_Excel_Piau_Zu_Im.py", + ] + }, { "type": "msedge", "request": "launch", diff --git "a/Documents/D300_\345\273\243\351\237\273_V3.xlsx" "b/Documents/D300_\345\273\243\351\237\273_V3.xlsx" index 8b16486..0db1bdc 100644 Binary files "a/Documents/D300_\345\273\243\351\237\273_V3.xlsx" and "b/Documents/D300_\345\273\243\351\237\273_V3.xlsx" differ diff --git a/Tai_Gi_Zu_Im_Bun.xlsx b/Tai_Gi_Zu_Im_Bun.xlsx new file mode 100644 index 0000000..04f9201 Binary files /dev/null and b/Tai_Gi_Zu_Im_Bun.xlsx differ diff --git a/Tai_Gi_Zu_Im_Bun_BAK.xlsx b/Tai_Gi_Zu_Im_Bun_BAK.xlsx new file mode 100644 index 0000000..124c883 Binary files /dev/null and b/Tai_Gi_Zu_Im_Bun_BAK.xlsx differ diff --git a/a700_Iong_Excel_Piau_Zu_Im.py b/a700_Iong_Excel_Piau_Zu_Im.py new file mode 100644 index 0000000..721af82 --- /dev/null +++ b/a700_Iong_Excel_Piau_Zu_Im.py @@ -0,0 +1,137 @@ +import getopt +import math +import os +import sys + +import xlwings as xw + +import settings +from p700_cu_zu_im import cu_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_input_file_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 = "Piau-Tsu-Im" + else: + CONVERT_FILE_NAME = file_path + print(f"CONVERT_FILE_NAME = {CONVERT_FILE_NAME}") + + # ========================================================================= + # (2) 分析已輸入的【台語音標】及【台語注音符號】,將之各別填入漢字之上、下方。 + # - 上方:台語音標 + # - 下方:台語注音符號 + # ========================================================================= + + # 打開一個新的或現有的 Excel 檔案 + wb = xw.Book('Tai_Gi_Zu_Im_Bun.xlsx') # 替換成你的 Excel 檔案名稱 + + # 選擇工作表 + # sheet = wb.sheets[0] # 選擇第一個工作表 + sheet = wb.sheets['漢字注音'] + + # 取得 V3 儲存格的字串 + v3_value = sheet.range('V3').value + + # 確認 V3 不為空 + if v3_value: + # 計算字串的總長度 + total_length = len(v3_value) + + # 每列最多處理 15 個字元,計算總共需要多少列 + chars_per_row = 15 + total_rows_needed = math.ceil(total_length / chars_per_row) # 無條件進位 + + # 逐行處理資料,從 Row 4 開始,每列處理 15 個字元 + row = 3 + for i in range(total_rows_needed): + for col in range(4, 19): # D列到R列, D=4, R=18 + cell_value = sheet.range((row, col)).value # 取得 D4, E4, ..., R4 的內容 + + # 確認內容不為空 + if cell_value: + # 分割字串來提取羅馬拼音和台語注音 + romaji = cell_value.split('〔')[1].split('〕')[0] # 取得〔羅馬拼音〕 + zhuyin = cell_value.split('【')[1].split('】')[0] # 取得【台語注音】 + + # 將羅馬拼音填入當前 row + 1 的儲存格 + sheet.range((row + 1, col)).value = romaji + + # 將台語注音填入當前 row + 3 的儲存格 + sheet.range((row + 3, col)).value = zhuyin + + # 每處理 15 個字元後,換到下一行 + row += 4 + + print("已完成【台語音標】和【台語注音符號】標註工作。") + + # ========================================================================= + # (4) 將已注音之「漢字注音表」,製作成 HTML 格式之「注音/拼音/標音」網頁。 + # ========================================================================= + # hoo_gua_tsu_im(CONVERT_FILE_NAME) + + # ========================================================================= + # (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) + + # 保存 Excel 檔案 + wb.save('Tai_Gi_Zu_Im_Bun.xlsx') + wb.close() diff --git a/docs/_test.html b/docs/_test.html new file mode 100644 index 0000000..5cdf62f --- /dev/null +++ b/docs/_test.html @@ -0,0 +1,70 @@ + + + + + 《上有力量的每日祈禱文》【雙排注音】 + + + + + + + + 美 + měi + + ㄇㄟˇ + + + + + + + + + 漢 + han3 + ㄏㄢ³ + 字 + ji7 + ㄖㄧ⁷ + + + + + + + + + \ No newline at end of file diff --git a/docs/assets/styles/test.css b/docs/assets/styles/test.css new file mode 100644 index 0000000..1d10e90 --- /dev/null +++ b/docs/assets/styles/test.css @@ -0,0 +1,242 @@ +@charset "UTF-8"; + +@import url("https://fonts.googleapis.com/css?family=Noto+Sans+TC&display=swap"); + +body { + font-family: 'Noto Sans TC', sans-serif !important; +} + +/* END: ed8c6549bwf9 */ + +@import url(https://fonts.googleapis.com/css?family=Noto+Serif+TC&display=swap); + +body { + font-family: 'Noto Serif TC', serif; +} + +@font-face { + font-family: 'BopomofoRuby'; + src: + local('BopomofoRuby1909-v1-Regular'), + url('../fonts/BopomofoRuby1909-v1-Regular.ttf'); +} + +body { + font-family: "Noto Serif TC", serif; + color: #333; + line-height: 1.8; +} + +header { + /* display: block; */ + border-top: #00c4ab 5px solid; + text-align: center; + background: url(../picts/bg_header.png) #e6e6e6; +} + +header h1 { + padding: 0 10px 25px; + font-family: 'Noto Serif TC', serif; + font-size: 32pt; + font-weight: bold; +} + +#articles { + font-size: 28pt; + font-weight: bold; +} + +button { + position: absolute; + top: 25px; + right: 15px; + background-color: transparent; + border: none; + cursor: pointer; +} + +button:focus { + outline: none; +} + +ul { + display: none; + list-style-type: none; +} + +li a { + text-decoration: none; + display: block; + padding: 17px 25px; + color: #FFF; + background: #B94B6A; + border-bottom: 1px solid #A24861; + font-size: 100%; + line-height: 1.0em; +} + +li:last-child a { + border-bottom: none; +} + +main { + display: block; + padding: 40px 20px 20px; + color: #333; + line-height: 1.8; +} + +p { + margin-bottom: 50px; + line-height: 2em; +} + +h1 { + color: #333; +} + +a { + color: #0066cc; + text-decoration: none; +} + +a:hover { + text-decoration: underline; +} + +rt { + font-family: Arial; + color: darkcyan; + font-size: 45%; + letter-spacing: 0; +} + +rtc { + font-family: BopomofoRuby; + color: #B94B6A; + font-size: 30%; + line-height: normal; + ruby-merge: merge; + + -webkit-ruby-position: inter-character; + ruby-position: inter-character; + text-orientation: upright; + letter-spacing: 0px; + + -webkitg_writing-mode: vertical-lr; + writing-mode: vertical-lr; + vertical-align: middle; + display: inline; +} + +/* 方音符號 */ +.zhu_yin { + font-family: "Noto Serif TC"; + font-size: 28pt; + letter-spacing: 0.2em; + line-height: 1.8; +} + +.zhu_yin ruby { + writing-mode: vertical-lr; + text-orientation: upright; + line-height: normal; +} + +.zhu_yin rt { + font-family: BopomofoRuby; + color: #B94B6A; + font-size: 40%; + letter-spacing: 0; +} + +.Piau_Im { + font-family: "Noto Serif TC"; + font-size: 28pt; + letter-spacing: 0.2em; + line-height: 1.8; +} + +.Piau_Im ruby { + writing-mode: vertical-lr; + text-orientation: upright; + line-height: normal; +} + +.Piau_Im rt { + font-family: BopomofoRuby; + color: #B94B6A; + font-size: 40%; + letter-spacing: 0; +} + +/* 雙排注音符號 */ +.Siang_Pai { + font-family: "Noto Serif TC"; + font-size: 28pt; + letter-spacing: 0.2em; + line-height: 1.8; +} + +.Siang_Pai rt { + font-family: Arial, Helvetica, sans-serif; + color: darkcyan; + font-size: 45%; + letter-spacing: 0; +} + +.Siang_Pai rtc { + font-family: BopomofoRuby; + color: #B94B6A; + font-size: 30%; + line-height: 1; + /* 控制行距 */ + letter-spacing: 0px; + + ruby-position: under; + /* text-orientation: mixed; + writing-mode: horizontal-tb; + padding-top: 0.1em; */ + /* 控制注音符號與漢字的間距 */ +} + +/* 台羅、閩拼、白話字 */ +.pin_yin { + font-family: "Noto Serif TC"; + font-size: 28pt; + letter-spacing: 0.2em; + line-height: 1.8; +} + +/* 白話字 */ +.poj { + font-family: "Noto Serif TC"; + font-size: 28pt; + letter-spacing: 0.2em; + line-height: 1.8; +} + +/* 十五音 */ +.fifteen_yin { + font-family: "Noto Serif TC"; + font-size: 28pt; + letter-spacing: 0.2em; + line-height: 1.8; +} + +.fifteen_yin rt { + letter-spacing: 0; + font-size: 40%; +} + +.title { + font-size: 1.2em; + letter-spacing: 2px; + text-align: center; +} + +.author { + font-size: 0.7em; + letter-spacing: 2px; + text-align: right; +} \ No newline at end of file diff --git a/p700_cu_zu_im.py b/p700_cu_zu_im.py new file mode 100644 index 0000000..8eec4e8 --- /dev/null +++ b/p700_cu_zu_im.py @@ -0,0 +1,101 @@ +# ========================================================================= +# 取注音( Cu-zu-im ): 分析已輸入的【台語音標】及【台語注音符號】,將之各別填入漢字之上、下方。 +# - 上方:台語音標 +# - 下方:台語注音符號 +# ========================================================================= +import xlwings as xw + + +def cu_zu_im(CONVERT_FILE_NAME): + # 打開活頁簿檔案 + file_path = CONVERT_FILE_NAME + wb = xw.Book(file_path) + + # 指定來源工作表 + source_sheet = wb.sheets["工作表1"] + source_sheet.select() + + # 取得工作表內總列數 + source_row_no = int( + source_sheet.range("A" + str(wb.sheets[0].cells.last_cell.row)).end("up").row + ) + print(f"source_row_no = {source_row_no}") + + # ========================================================== + # 備妥程式需使用之工作表 + # ========================================================== + sheet_name_list = [ + "缺字表", + "字庫表", + "漢字注音表", + ] + # ----------------------------------------------------- + # 檢查工作表是否已存在 + for sheet_name in sheet_name_list: + sheets = [sheet.name for sheet in wb.sheets] # 獲取所有工作表的名稱 + if sheet_name in sheets: + sheet = wb.sheets[sheet_name] + try: + sheet.select() + sheet.clear() + continue + except Exception as e: + print(e) + else: + # CommandError 的 Exception 發生時,表工作表不存在 + # 新增程式需使用之工作表 + print(f"工作表 {sheet_name} 不存在,正在新增...") + wb.sheets.add(name=sheet_name) + + # 選用「漢字注音表」 + try: + han_ji_tsu_im_paiu = wb.sheets["漢字注音表"] + han_ji_tsu_im_paiu.select() + except Exception as e: + # 处理找不到 "漢字注音表" 工作表的异常 + print(e) + print("找不到:〖漢字注音表〗工作表。") + return False + + # ----------------------------------------------------- + # 將「字串」轉換成「串列(Characters List)」 + # Python code to convert string to list character-wise + def convert_string_to_chars_list(string): + list1 = [] + list1[:0] = string + return list1 + + # ========================================================== + # (1) + # ========================================================== + # 自【工作表1】的每一列,讀入一個「段落」的漢字。然後將整個段 + # 落拆成「單字」,存到【漢字注音表】;在【漢字注音表】的每個 + # 儲存格,只存放一個「單字」。 + # ========================================================== + + source_row_index = 1 + target_row_index = 1 # index for target sheet + # for row in range(1, source_rows): + while source_row_index <= source_row_no: + # 自【工作表1】取得「一行漢字」 + tsit_hang_ji = str(source_sheet.range("A" + str(source_row_index)).value) + hang_ji_str = tsit_hang_ji.strip() + + # 讀到空白行 + if hang_ji_str == "None": + hang_ji_str = "\n" + else: + hang_ji_str = f"{tsit_hang_ji}\n" + + han_ji_range = convert_string_to_chars_list(hang_ji_str) + + # ========================================================= + # 讀到的整段文字,以「單字」形式寫入【漢字注音表】。 + # ========================================================= + han_ji_tsu_im_paiu.range("A" + str(target_row_index)).options( + transpose=True + ).value = han_ji_range + + ji_soo = len(han_ji_range) + target_row_index += ji_soo + source_row_index += 1
+ + 美 + měi + + ㄇㄟˇ + + +
+ + + 漢 + han3 + ㄏㄢ³ + 字 + ji7 + ㄖㄧ⁷ + + +