Skip to content

Commit

Permalink
新增漢字標音功能:十五音
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Nov 7, 2024
1 parent 173fcdc commit 17164d8
Show file tree
Hide file tree
Showing 13 changed files with 716 additions and 8 deletions.
11 changes: 9 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@
"console": "integratedTerminal",
},
{
"name": "a704_批次式查找及填入漢字標音",
"name": "a704_製作其它漢字標音",
"type": "debugpy",
"request": "launch",
"program": "a704_批次式查找及填入漢字標音.py",
"program": "a704_製作其它漢字標音.py",
"console": "integratedTerminal",
},
{
"name": "a710_批次式漢字標音及網頁製作",
"type": "debugpy",
"request": "launch",
"program": "a710_批次式漢字標音及網頁製作.py",
"console": "integratedTerminal",
},
{
Expand Down
Binary file modified Documents/白話音/河洛話_漢字庫.xlsx
Binary file not shown.
Binary file modified Ho_Lok_Ue.db
Binary file not shown.
7 changes: 6 additions & 1 deletion a702_查找及填入漢字標音.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import xlwings as xw

from mod_file_access import get_han_ji_khoo, get_sound_type
from mod_file_access import (
copy_excel_sheet,
get_han_ji_khoo,
get_sound_type,
reset_han_ji_piau_im_cells,
)
from p702_Ca_Han_Ji_Thak_Im import ca_han_ji_thak_im

# from p703_Kong_Un_Ca_Thak_Im import ca_han_ji_thak_im
Expand Down
9 changes: 5 additions & 4 deletions a703_製作標音網頁.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
file_name = wb.name
print(f"檔案名稱: {file_name}")

# 顯示「已輸入之拼音字母及注音符號」
# 顯示「已輸入之拼音字母及注音符號」
# named_range = wb.names['顯示注音輸入'] # 選擇名為 "顯示注音輸入" 的命名範圍# 選擇名為 "顯示注音輸入" 的命名範圍
# named_range.refers_to_range.value = True
named_range = get_named_value(wb, '顯示注音輸入', True)
Expand All @@ -37,7 +37,8 @@
sheet.range('A1').select() # 將 A1 儲存格設為作用儲存格

# (2) A740: 將【漢字注音】工作表的內容,轉成 HTML 網頁檔案。
tng_sing_bang_iah(wb, '漢字注音', 'V3')
# tng_sing_bang_iah(wb, '漢字注音', 'V3')
tng_sing_bang_iah(wb, '十五音', 'V3')

# (3) A750: 將 Tai_Gi_Zu_Im_Bun.xlsx 檔案,依 env 工作表的設定,另存新檔到指定目錄。
try:
Expand All @@ -51,9 +52,9 @@
).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
new_file_path = os.path.join(
".\\{0}".format(output_path),
".\\{0}".format(output_path),
f"【河洛話注音】{file_name}.xlsx")

# 儲存新建立的工作簿
Expand Down
67 changes: 67 additions & 0 deletions a704_製作其它漢字標音.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
import sys

import xlwings as xw

from mod_file_access import copy_excel_sheet, reset_han_ji_piau_im_cells
from p704_漢字以十五音標注音 import zap_goo_im_piau_im

# from p703_Kong_Un_Ca_Thak_Im import ca_han_ji_thak_im

# (0) 取得專案根目錄。
# 使用已打開且處於作用中的 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}")

# 顯示「已輸入之拼音字母及注音符號」
named_range = wb.names['顯示注音輸入'] # 選擇名為 "顯示注音輸入" 的命名範圍# 選擇名為 "顯示注音輸入" 的命名範圍
named_range.refers_to_range.value = True

# (1) A720: 將 V3 儲存格內的漢字,逐個填入標音用方格。
sheet = wb.sheets['漢字注音'] # 選擇工作表
sheet.activate() # 將「漢字注音」工作表設為作用中工作表
sheet.range('A1').select() # 將 A1 儲存格設為作用儲存格

# (2) 複製【漢字注音】工作表,並將【漢字注音】工作表已有漢字標清除(不含上列之【台語音標】)
# copy_excel_sheet(wb, '漢字注音', '十五音')
reset_han_ji_piau_im_cells(wb, '十五音')
zap_goo_im_piau_im(wb, sheet_name='十五音', cell='V3', hue_im="白話音")

# (3) A740: 將【漢字注音】工作表的內容,轉成 HTML 網頁檔案。
# tng_sing_bang_iah(wb, '漢字注音', 'V3')

# (4) A750: 將 Tai_Gi_Zu_Im_Bun.xlsx 檔案,依 env 工作表的設定,另存新檔到指定目錄。
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
except KeyError:
# print("未找到命名範圍 'TITLE',使用預設名稱")
# file_name = "default_file_name.xlsx" # 提供一個預設檔案名稱
setting_sheet = wb.sheets["env"]
file_name = str(
setting_sheet.range("C4").value
).strip()

# 設定檔案輸出路徑,存於專案根目錄下的 output2 資料夾
output_path = wb.names['OUTPUT_PATH'].refers_to_range.value
new_file_path = os.path.join(
".\\{0}".format(output_path),
f"【河洛話注音】{file_name}.xlsx")

# 儲存新建立的工作簿
wb.save(new_file_path)

# 保存 Excel 檔案
# wb.close()

Loading

0 comments on commit 17164d8

Please sign in to comment.