Skip to content

Commit

Permalink
加【蘭亭集序】
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Nov 5, 2024
1 parent fddc32c commit 8667c46
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"console": "integratedTerminal",
},
{
"name": "a700_産生作業用工作暫存檔",
"name": "a700_重置漢字標音工作表",
"type": "debugpy",
"request": "launch",
"program": "a700_産生作業用工作暫存檔.py",
"program": "a700_重置漢字標音工作表.py",
"console": "integratedTerminal",
},
{
Expand Down
Binary file modified Ho_Lok_Ue.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,28 @@
print("無法執行,可能原因:(1) 未指定輸入檔案;(2) 未找到作用中的 Excel 工作簿")
sys.exit(2)

#--------------------------------------------------------------------------
# 將儲存格內的舊資料清除
#--------------------------------------------------------------------------
sheet = wb.sheets['漢字注音'] # 選擇工作表
sheet.activate() # 將「漢字注音」工作表設為作用中工作表
sheet.range('A1').select() # 將 A1 儲存格設為作用儲存格

total_rows = wb.names['每頁總列數'].refers_to_range.value
cells_per_row = 4
end_of_rows = int((total_rows * cells_per_row ) + 2)
cells_range = f'D3:R{end_of_rows}'

sheet.range(cells_range).clear_contents() # 清除 C3:R{end_of_row} 範圍的內容

# 獲取 V3 儲存格的合併範圍
merged_range = sheet.range('V3').merge_area
# 清空合併儲存格的內容
merged_range.clear_contents()

#--------------------------------------------------------------------------
# 將待注音的【漢字儲存格】,文字顏色重設為黑色(自動 RGB: 0, 0, 0);填漢顏色重設為無填滿
#--------------------------------------------------------------------------
reset_han_ji_cells(wb)

# 將檔案存放路徑設為【專案根目錄】之下
Expand Down
10 changes: 10 additions & 0 deletions a701_作業中活頁檔填入漢字.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import xlwings as xw

from mod_file_access import get_han_ji_khoo, get_sound_type
from p702_Ca_Han_Ji_Thak_Im import ca_han_ji_thak_im
from p709_reset_han_ji_cells import reset_han_ji_cells
from p710_thiam_han_ji import fill_hanji_in_cells

Expand Down Expand Up @@ -41,6 +43,14 @@
# 將待注音的漢字填入
fill_hanji_in_cells(wb)

# A731: 自動為漢字查找讀音,並抄寫到漢字的上方(拼音)及下方(注音)。
type = get_sound_type(wb)
han_ji_khoo = get_han_ji_khoo(wb)
if han_ji_khoo == "河洛話":
ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', hue_im="白話音", han_ji_khoo="河洛話", db_name='Ho_Lok_Ue.db', module_name='mod_河洛話', function_name='han_ji_ca_piau_im')
else:
ca_han_ji_thak_im(wb, sheet_name='漢字注音', cell='V3', hue_im="文讀音", han_ji_khoo="廣韻", db_name='Kong_Un.db', module_name='mod_廣韻', function_name='han_ji_ca_piau_im')

# 將檔案存放路徑設為【專案根目錄】之下
try:
file_name = str(wb.names['TITLE'].refers_to_range.value).strip()
Expand Down
52 changes: 52 additions & 0 deletions a708_清除已填入之漢字.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import sys
from pathlib import Path

import xlwings as xw

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

# 專案根目錄
project_root = current_file_path.parent

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

# =========================================================================
# 若無指定輸入檔案,則獲取當前作用中的 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.activate() # 將「漢字注音」工作表設為作用中工作表
sheet.range('A1').select() # 將 A1 儲存格設為作用儲存格

# 每頁最多處理的列數
TOTAL_ROWS = int(wb.names['每頁總列數'].refers_to_range.value) # 從名稱【每頁總列數】取得值
# 每列最多處理的字數
CHARS_PER_ROW = int(wb.names['每列總字數'].refers_to_range.value) # 從名稱【每列總字數】取得值

#--------------------------------------------------------------------------
# 將儲存格內的舊資料清除
#--------------------------------------------------------------------------
end_of_rows = int((TOTAL_ROWS * CHARS_PER_ROW ) + 2)
cells_range = f'D3:R{end_of_rows}'

sheet.range(cells_range).clear_contents() # 清除 C3:R{end_of_row} 範圍的內容

File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions p709_reset_han_ji_cells.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import xlwings as xw


#--------------------------------------------------------------------------
# 將待注音的【漢字儲存格】,文字顏色重設為黑色(自動 RGB: 0, 0, 0);填漢顏色重設為無填滿
#--------------------------------------------------------------------------
def reset_han_ji_cells(wb, sheet_name='漢字注音'):
# 選擇指定的工作表
sheet = wb.sheets[sheet_name]
sheet.activate() # 將「漢字注音」工作表設為作用中工作表
sheet.range('A1').select() # 將 A1 儲存格設為作用儲存格

# 每頁最多處理的列數
TOTAL_ROWS = int(wb.names['每頁總列數'].refers_to_range.value) # 從名稱【每頁總列數】取得值
Expand Down

0 comments on commit 8667c46

Please sign in to comment.