Skip to content

Commit

Permalink
標注漢字讀音的產出,其存放目錄名稱,自 docs 改成 output 。原 docs 目錄名稱歸 "系統開發及維護文件" 使用。
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Mar 7, 2024
1 parent 91372e9 commit cbea435
Show file tree
Hide file tree
Showing 57 changed files with 2,215 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
INPUT_FILE_PATH=d:\work\Piau-Im\docs
INPUT_FILE_PATH=d:\work\Piau-Im\output
FILE_NAME=Piau-Tsu-Im.xlsx
TITLE=漢字標注音
IMAGE_URL=https://www.merit-times.com/news_pic/20211220/C20211219211546468.jpg
2 changes: 1 addition & 1 deletion a100_予我漢字注音.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def myfunc(argv):
setting_sheet.range("C4").value
).strip()
new_file_path = os.path.join(
".\\docs",
".\\output",
f"【河洛話注音】{new_file_name}" + ".xlsx")

# 儲存新建立的工作簿
Expand Down
2 changes: 1 addition & 1 deletion a200_漢字補注音.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def myfunc(argv):
setting_sheet.range("C4").value
).strip()
new_file_path = os.path.join(
".\\docs",
".\\output",
f"【河洛話注音】{new_file_name}" + ".xlsx")

# 儲存新建立的工作簿
Expand Down
14 changes: 7 additions & 7 deletions fun_e_ji_tsa_un_bu.py → fun_ha_ji_tsa_un_bu.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import xlwings as xw

def e_ji_tsa_un_bu(e_ji):
def ha_ji_tsa_un_bu(ha_ji):
try:
# 使用 xlwings 打開 Excel 檔案
file_path = r'.\\tools\\反切下字與韻母對映表.xlsx'
wb = xw.Book(file_path)
sheet = wb.sheets['反切下字表']

# 查找 e_ji 在指定範圍 (J2:J187) 的位置
# 查找 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 e_ji in words:
# 如果找到了 e_ji,則記錄下其相對映之 "列號",並從相關欄位獲取資料
if ha_ji in words:
# 如果找到了 ha_ji,則記錄下其相對映之 "列號",並從相關欄位獲取資料
data = {
"id": row - 1, # 第一行為標題行,故實際列號需要減1
"liap": sheet.range(f'B{row}').value, # 攝
Expand All @@ -28,13 +28,13 @@ def e_ji_tsa_un_bu(e_ji):
wb.close() # 處理完成後關閉工作簿
return data
wb.close() # 如果沒找到,也關閉工作簿
return None # 如果在範圍內沒有找到 e_ji,返回 None
return None # 如果在範圍內沒有找到 ha_ji,返回 None
except Exception as e:
print(f"發生錯誤:{e}")
return None


# 測試函數
e_ji = "荅" # 假設的反切上字
result = e_ji_tsa_un_bu(e_ji)
ha_ji = "荅" # 假設的反切上字
result = ha_ji_tsa_un_bu(ha_ji)
print(result)
2 changes: 1 addition & 1 deletion m100_建立標注音檔案.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main():
# 2. 將子目錄 ./docs 的檔案: env.xlsx ,其中名稱為:env 的工作表,複製到這個
# ===============================================================================
# 新建立的 Excel 檔案中指定 env.xlsx 檔案的路徑
source_file_path = os.path.join("./docs", "env.xlsx")
source_file_path = os.path.join("./output", "env.xlsx")

# 開啟 env.xlsx 檔案
source_wb = xw.Book(source_file_path)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit cbea435

Please sign in to comment.