refactor: migrate configuration to .env file for better environment management
- Replace hardcoded file paths with environment variables in extract_vba.py and import_vba.py - Add .env file for local configuration (excluded from git via .gitignore) - Add python-dotenv dependency for environment variable loading - Maintain fallback to interactive mode when environment variables are not set Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,11 +11,17 @@ import re
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Tuple, Optional
|
||||
|
||||
# 加载 .env 配置文件
|
||||
try:
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
except ImportError:
|
||||
print("警告: 未安装 python-dotenv 库,将使用默认配置")
|
||||
print("建议运行: pip install python-dotenv")
|
||||
|
||||
# ==================== 配置区域 ====================
|
||||
# 在此配置要处理的xlsm文件路径
|
||||
# 支持相对路径(相对于脚本所在目录)或绝对路径
|
||||
# 留空或设为None则使用交互模式(自动查找Excel文件夹)
|
||||
TARGET_XLSM_FILE = r"C:\Users\Administrator\Desktop\新BOM\AutoBOM\YTHN-100.A0.532-BOM-1.2版 Claude.xlsm" # 例如: r"Excel\myfile.xlsm" 或 r"D:\path\to\file.xlsm"
|
||||
# 从 .env 文件读取配置,如果未设置则使用 None(交互模式)
|
||||
TARGET_XLSM_FILE = os.getenv("TARGET_XLSM_FILE", "").strip() or None
|
||||
# =================================================
|
||||
|
||||
# VBA项目相关常量
|
||||
|
||||
Reference in New Issue
Block a user