Skip to content

Commit

Permalink
優化程式碼架構
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanJui committed Jan 11, 2025
1 parent 780dc20 commit 3583ad5
Show file tree
Hide file tree
Showing 14 changed files with 422 additions and 798 deletions.
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
// 如需詳細資訊,請瀏覽: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "a705_輸出己標音漢字",
"type": "debugpy",
"request": "launch",
"program": "a705_輸出己標音漢字.py",
"console": "integratedTerminal",
},
{
"name": "csv01_更新漢字表資料",
"type": "debugpy",
Expand Down Expand Up @@ -53,6 +46,13 @@
"program": "a704_製作其它漢字標音.py",
"console": "integratedTerminal",
},
{
"name": "a705_輸出己標音漢字",
"type": "debugpy",
"request": "launch",
"program": "a705_輸出己標音漢字.py",
"console": "integratedTerminal",
},
{
"name": "a710_批次式漢字標音及網頁製作",
"type": "debugpy",
Expand Down
18 changes: 12 additions & 6 deletions a700_重置漢字標音工作表.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dotenv import load_dotenv

# 載入自訂模組
from mod_file_access import save_as_new_file
from p709_reset_han_ji_cells import reset_han_ji_cells

# =========================================================================
Expand All @@ -36,8 +37,9 @@ def logging_process_step(msg):
logging.info(msg)

# =========================================================================
# 定義 Exit Code
# 常數定義
# =========================================================================
# 定義 Exit Code
EXIT_CODE_SUCCESS = 0 # 成功
EXIT_CODE_NO_FILE = 1 # 無法找到檔案
EXIT_CODE_INVALID_INPUT = 2 # 輸入錯誤
Expand All @@ -48,9 +50,9 @@ def logging_process_step(msg):
# 作業程序
# =========================================================================
def process(wb):
#--------------------------------------------------------------------------
#----------------------------------------------------------------------
# 將儲存格內的舊資料清除
#--------------------------------------------------------------------------
#----------------------------------------------------------------------
sheet = wb.sheets['漢字注音'] # 選擇工作表
sheet.activate() # 將「漢字注音」工作表設為作用中工作表
sheet.range('A1').select() # 將 A1 儲存格設為作用儲存格
Expand Down Expand Up @@ -80,9 +82,13 @@ def process(wb):
#--------------------------------------------------------------------------
# 作業結尾處理
#--------------------------------------------------------------------------
wb.save()
return EXIT_CODE_SUCCESS

file_path = save_as_new_file(wb=wb)
if not file_path:
logging.error("儲存檔案失敗!")
return EXIT_CODE_PROCESS_FAILURE # 作業異當終止:無法儲存檔案
else:
logging_process_step(f"儲存檔案至路徑:{file_path}")
return EXIT_CODE_SUCCESS # 作業正常結束

# =============================================================================
# 程式主流程
Expand Down
12 changes: 8 additions & 4 deletions a701_作業中活頁檔填入漢字.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ def logging_process_step(msg):
logging.info(msg)

# =========================================================================
# 定義 Exit Code
# 常數定義
# =========================================================================
# 定義 Exit Code
EXIT_CODE_SUCCESS = 0 # 成功
EXIT_CODE_NO_FILE = 1 # 無法找到檔案
EXIT_CODE_INVALID_INPUT = 2 # 輸入錯誤
Expand Down Expand Up @@ -110,9 +111,12 @@ def process(wb):
# 作業結尾處理
# ---------------------------------------------------------------------
file_path = save_as_new_file(wb=wb)
logging.info("己存檔至路徑:{file_path}")
return EXIT_CODE_SUCCESS

if not file_path:
logging.error("儲存檔案失敗!")
return EXIT_CODE_PROCESS_FAILURE # 作業異當終止:無法儲存檔案
else:
logging_process_step(f"儲存檔案至路徑:{file_path}")
return EXIT_CODE_SUCCESS # 作業正常結束

# =============================================================================
# 程式主流程
Expand Down
89 changes: 0 additions & 89 deletions a701_作業中活頁檔填入漢字_ R2.py

This file was deleted.

141 changes: 0 additions & 141 deletions a701_作業中活頁檔填入漢字_R1.py

This file was deleted.

Loading

0 comments on commit 3583ad5

Please sign in to comment.