Skip to content

Commit

Permalink
改善【批次式】自動填入台羅音標及台語注音符號作法。
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Oct 4, 2024
1 parent 0335c3b commit b629dc3
Show file tree
Hide file tree
Showing 31 changed files with 2,958 additions and 19 deletions.
21 changes: 14 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "a701_作業中活頁檔填入漢字",
"type": "debugpy",
"request": "launch",
"program": "a701_作業中活頁檔填入漢字.py",
"console": "integratedTerminal",
},
{
"name": "a702_Batch_Zu_Tong_Piau_Zu_Im",
"type": "debugpy",
"request": "launch",
"program": "a702_Batch_Zu_Tong_Piau_Zu_Im.py",
"console": "integratedTerminal",
},
{
"name": "p711_TL_Tng_Zu_Im",
"type": "debugpy",
Expand All @@ -25,13 +39,6 @@
"program": "mod_雅俗通.py",
"console": "integratedTerminal",
},
{
"name": "a702_Batch_Zu_Tong_Piau_Zu_Im",
"type": "debugpy",
"request": "launch",
"program": "a702_Batch_Zu_Tong_Piau_Zu_Im.py",
"console": "integratedTerminal",
},
{
"name": "a710_清理原填入漢字及注音",
"type": "debugpy",
Expand Down
69 changes: 69 additions & 0 deletions a701_作業中活頁檔填入漢字.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import getopt
import os
import sys
from pathlib import Path

import xlwings as xw

from p710_thiam_han_ji import fill_hanji_in_cells

# =========================================================================
# (1) 取得專案根目錄。
# =========================================================================
# 獲取當前檔案的路徑
current_file_path = Path(__file__).resolve()

# 專案根目錄
project_root = current_file_path.parent

print(f"專案根目錄為: {project_root}")

# =========================================================================
# (2) 若無指定輸入檔案,則獲取當前作用中的 Excel 檔案並另存新檔。
# =========================================================================
wb = None
# 使用已打開且處於作用中的 Excel 工作簿
try:
# 嘗試獲取當前作用中的 Excel 工作簿
wb = xw.apps.active.books.active
except Exception as e:
print(f"發生錯誤: {e}")
print("無法找到作用中的 Excel 工作簿")
sys.exit(2)

if not wb:
print("無法執行,可能原因:(1) 未指定輸入檔案;(2) 未找到作用中的 Excel 工作簿")
sys.exit(2)

# 清空儲存格內容
sheet = wb.sheets['漢字注音']
sheet.range('D3:R166').clear_contents() # 清除 C3:R166 範圍的內容

# 將待注音的漢字填入
fill_hanji_in_cells(wb)

# 將檔案存放路徑設為【專案根目錄】之下
file_name = "Tai_Gi_Zu_Im_Bun.xlsx"
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)

# 關閉工作簿
wb.close()

print(f"檔案已成功存為 {new_file_path}")
30 changes: 18 additions & 12 deletions a702_Batch_Zu_Tong_Piau_Zu_Im.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@

# 所有檔案名稱
files = [
"【河洛話注音】金剛般若波羅蜜經001。法會因由分第一.xlsx",
# "【河洛話注音】金剛般若波羅蜜經001。法會因由分第一.xlsx",
# "【河洛話注音】金剛般若波羅蜜經002。善現啟請分第二.xlsx",
# "【河洛話注音】金剛般若波羅蜜經003。大乘正宗分第三.xlsx",
# "【河洛話注音】金剛般若波羅蜜經004。妙行無住分第四.xlsx",
# "【河洛話注音】金剛般若波羅蜜經005。如理實見分第五.xlsx",
# "【河洛話注音】金剛般若波羅蜜經006。正信希有分第六.xlsx",
# "【河洛話注音】金剛般若波羅蜜經007。無得無說分第七.xlsx",
# "【河洛話注音】金剛般若波羅蜜經009。一相無相分第九.xlsx",
# "【河洛話注音】金剛般若波羅蜜經010。莊嚴淨土分第十.xlsx",
# "【河洛話注音】金剛般若波羅蜜經011。無為福勝分第十一.xlsx",
# "【河洛話注音】金剛般若波羅蜜經012。尊重正教分第十二.xlsx",
# "【河洛話注音】金剛般若波羅蜜經013。如法受持分第十三.xlsx"
"【河洛話注音】金剛般若波羅蜜經008。依法出生分第八.xlsx",
"【河洛話注音】金剛般若波羅蜜經009。一相無相分第九.xlsx",
"【河洛話注音】金剛般若波羅蜜經010。莊嚴淨土分第十.xlsx",
"【河洛話注音】金剛般若波羅蜜經011。無為福勝分第十一.xlsx",
"【河洛話注音】金剛般若波羅蜜經012。尊重正教分第十二.xlsx",
"【河洛話注音】金剛般若波羅蜜經013。如法受持分第十三.xlsx"
]

# 迴圈遍歷所有檔案並依次執行 Python 檔案
Expand All @@ -51,16 +52,21 @@
tng_sing_bang_iah(wb, '漢字注音', 'V3')

# (4) A750: 將 Tai_Gi_Zu_Im_Bun.xlsx 檔案,依 env 工作表的設定,另存新檔到指定目錄。
setting_sheet = wb.sheets["env"]
new_file_name = str(
setting_sheet.range("C4").value
).strip()

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"【河洛話注音】{new_file_name}" + ".xlsx")
f"【河洛話注音】{file_name}.xlsx")

# 儲存新建立的工作簿
wb.save(new_file_path)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

<!DOCTYPE html>
<html lang="zh-TW">
<head>
<title>《金剛般若波羅蜜經001。法會因由分第一》【漢字注音】</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="assets/styles/styles.css">
</head>
<body>
《金剛般若波羅蜜經001。法會因由分第一》【漢字注音】
<div class='separator' style='clear: both'>
<a href='圖片' style='display: block; padding: 1em 0; text-align: center'>
<img alt='金剛般若波羅蜜經001。法會因由分第一' border='0' width='400' data-original-height='630' data-original-width='1200'
src='https://shoplineimg.com/5db585d59db3cb0012a18bce/5f2a9d3f30cc6200455c1c25/1296x.webp?source_format=jpg' />
</a>
</div>

<div class='Siang_Pai'><p>
<span></span>
<ruby><rb></rb><rt>kim1</rt><rtc>ㄍㄧㆬ˙</rtc></ruby>
<ruby><rb></rb><rt>kong1</rt><rtc>ㄍㆲ˙</rtc></ruby>
<ruby><rb></rb><rt>puann1</rt><rtc>ㄅㄨㆩ˙</rtc></ruby>
<ruby><rb></rb><rt>jiok4</rt><rtc>ㆡㄧㆦㆻ</rtc></ruby>
<ruby><rb></rb><rt>phoo¹</rt><rtc>ㄆㆦˉ</rtc></ruby>
<ruby><rb></rb><rt>lo5</rt><rtc>ㄌㄜˊ</rtc></ruby>
<ruby><rb></rb><rt>bit8</rt><rtc>ㆠㄧㆵ˙</rtc></ruby>
<ruby><rb></rb><rt>king1</rt><rtc>ㄍㄧㄥ˙</rtc></ruby>
<span></span>
</p><p>
<ruby><rb></rb><rt>huat4</rt><rtc>ㄏㄨㄚㆵ</rtc></ruby>
<ruby><rb></rb><rt>e6</rt><rtc>ㆤˋ</rtc></ruby>
<ruby><rb></rb><rt>in1</rt><rtc>ㄧㄣ˙</rtc></ruby>
<ruby><rb></rb><rt>iu5</rt><rtc>ㄧㄨˊ</rtc></ruby>
<ruby><rb></rb><rt>hun1</rt><rtc>ㄏㄨㄣ˙</rtc></ruby>
<ruby><rb></rb><rt>te7</rt><rtc>ㄉㆤ˪</rtc></ruby>
<ruby><rb></rb><rt>it4</rt><rtc>ㄧㆵ</rtc></ruby>
</p><p>
<ruby><rb></rb><rt>ju5</rt><rtc>ㆡㄨˊ</rtc></ruby>
<ruby><rb></rb><rt>si6</rt><rtc>ㄙㄧˋ</rtc></ruby>
<ruby><rb></rb><rt>ngoo2</rt><rtc>ㄫㆦˋ</rtc></ruby>
<ruby><rb></rb><rt>bun5</rt><rtc>ㆠㄨㄣˊ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>it4</rt><rtc>ㄧㆵ</rtc></ruby>
<ruby><rb></rb><rt>si5</rt><rtc>ㄙㄧˊ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>put8</rt><rtc>ㄅㄨㆵ˙</rtc></ruby>
<ruby><rb></rb><rt>tsai6</rt><rtc>ㄗㄞˋ</rtc></ruby>
<ruby><rb></rb><rt></rt><rtc></rtc></ruby>
<ruby><rb></rb><rt>ue7</rt><rtc>ㄨㆤ˪</rtc></ruby>
<ruby><rb></rb><rt>kok4</rt><rtc>ㄍㆦㆻ</rtc></ruby>
<ruby><rb></rb><rt>ki5</rt><rtc>ㄍㄧˊ</rtc></ruby>
<ruby><rb></rb><rt>tshiu7</rt><rtc>ㄘㄧㄨ˪</rtc></ruby>
<ruby><rb></rb><rt>kip4</rt><rtc>ㄍ一ㆴ</rtc></ruby>
<ruby><rb></rb><rt>koo1</rt><rtc>ㄍㆦ˙</rtc></ruby>
<ruby><rb></rb><rt>tak8</rt><rtc>ㄉㄚㆻ˙</rtc></ruby>
<ruby><rb></rb><rt>uan5</rt><rtc>ㄨㄢˊ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>ir2</rt><rtc>ˋ</rtc></ruby>
<ruby><rb></rb><rt>tua7</rt><rtc>ㄉㄨㄚ˪</rtc></ruby>
<ruby><rb></rb><rt>pi2</rt><rtc>ㄅㄧˋ</rtc></ruby>
<ruby><rb></rb><rt>khu1</rt><rtc>ㄎㄨ˙</rtc></ruby>
<ruby><rb></rb><rt>tsing3</rt><rtc>ㄗㄧㄥ˫</rtc></ruby>
<ruby><rb></rb><rt>tshainn1</rt><rtc>ㄘㆮ˙</rtc></ruby>
<ruby><rb></rb><rt>ji7</rt><rtc>ㆡㄧ˪</rtc></ruby>
<ruby><rb></rb><rt>pah4</rt><rtc>ㄅㄚㆷ</rtc></ruby>
<ruby><rb></rb><rt>goo6</rt><rtc>ㆣㆦˋ</rtc></ruby>
<ruby><rb></rb><rt>tsap8</rt><rtc>ㄗㄚㆴ˙</rtc></ruby>
<ruby><rb></rb><rt>jin⁵</rt><rtc>ㆢㄧㄣˊ</rtc></ruby>
<ruby><rb></rb><rt>ku1</rt><rtc>ㄍㄨ˙</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>nia7</rt><rtc>ㄋㄧㄚ˪</rtc></ruby>
<ruby><rb></rb><rt>si5</rt><rtc>ㄙㄧˊ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>se3</rt><rtc>ㄙㆤ˫</rtc></ruby>
<ruby><rb></rb><rt>tsun1</rt><rtc>ㄗㄨㄣ˙</rtc></ruby>
<ruby><rb></rb><rt>sit8</rt><rtc>ㄙㄧㆵ˙</rtc></ruby>
<ruby><rb></rb><rt>si5</rt><rtc>ㄙㄧˊ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>tio0</rt><rtc>ㄉㄧㄜ˙</rtc></ruby>
<ruby><rb></rb><rt>i1</rt><rtc>ㄧ˙</rtc></ruby>
<ruby><rb></rb><rt>ti5</rt><rtc>ㄉㄧˊ</rtc></ruby>
<ruby><rb></rb><rt>puat4</rt><rtc>ㄅㄨㄚㆵ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>jip8</rt><rtc>ㆡ一ㆴ˙</rtc></ruby>
<ruby><rb></rb><rt></rt><rtc></rtc></ruby>
<ruby><rb></rb><rt>ue7</rt><rtc>ㄨㆤ˪</rtc></ruby>
<ruby><rb></rb><rt>tua7</rt><rtc>ㄉㄨㄚ˪</rtc></ruby>
<ruby><rb></rb><rt>siann5</rt><rtc>ㄙˊ</rtc></ruby>
<ruby><rb></rb><rt>khit4</rt><rtc>ㄎㄧㆵ</rtc></ruby>
<ruby><rb></rb><rt>sit8</rt><rtc>ㄙㄧㆵ˙</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>u1</rt><rtc>ㄨ˙</rtc></ruby>
<ruby><rb></rb><rt>ki5</rt><rtc>ㄍㄧˊ</rtc></ruby>
<ruby><rb></rb><rt>siann5</rt><rtc>ㄙˊ</rtc></ruby>
<ruby><rb></rb><rt>tiong1</rt><rtc>ㄉㄧㆲ˙</rtc></ruby>
<ruby><rb></rb><rt>tshur3</rt><rtc>ㄘ˫</rtc></ruby>
<ruby><rb></rb><rt>te7</rt><rtc>ㄉㆤ˪</rtc></ruby>
<ruby><rb></rb><rt>khit4</rt><rtc>ㄎㄧㆵ</rtc></ruby>
<ruby><rb></rb><rt>i2</rt><rtc>ㄧˋ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>huan5</rt><rtc>ㄏㄨㄢˊ</rtc></ruby>
<ruby><rb></rb><rt>tsi3</rt><rtc>ㄗㄧ˫</rtc></ruby>
<ruby><rb></rb><rt>puinn2</rt><rtc>ㄅㄨㆪˋ</rtc></ruby>
<ruby><rb></rb><rt>tshir3</rt><rtc>ㄘ˫</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>puinn7</rt><rtc>ㄅㄨㆪ˪</rtc></ruby>
<ruby><rb></rb><rt>sit8</rt><rtc>ㄙㄧㆵ˙</rtc></ruby>
<ruby><rb></rb><rt>git4</rt><rtc>ㆣㄧㆵ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>siu1</rt><rtc>ㄙㄧㄨ˙</rtc></ruby>
<ruby><rb></rb><rt>i1</rt><rtc>ㄧ˙</rtc></ruby>
<ruby><rb></rb><rt>puat4</rt><rtc>ㄅㄨㄚㆵ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>se2</rt><rtc>ㄙㆤˋ</rtc></ruby>
<ruby><rb></rb><rt>tsiok4</rt><rtc>ㄗㄧㆦㆻ</rtc></ruby>
<ruby><rb></rb><rt>i2</rt><rtc>ㄧˋ</rtc></ruby>
<span></span>
<ruby><rb></rb><rt>hu1</rt><rtc>ㄏㄨ˙</rtc></ruby>
<ruby><rb></rb><rt>tso7</rt><rtc>ㄗㄜ˪</rtc></ruby>
<ruby><rb></rb><rt>ji5</rt><rtc>ㆡㄧˊ</rtc></ruby>
<ruby><rb></rb><rt>tser6</rt><rtc>ㄗˋ</rtc></ruby>
<span></span>
</p></div>
</body>
</html>

Loading

0 comments on commit b629dc3

Please sign in to comment.