refactor: 重构文件读取和日志处理以提升性能和稳定性

- 新增 smart_read_excel 工具函数,统一 Excel 读取逻辑并自动选择引擎
- 重构 ConfigManager.get_path 方法,使用 pathlib 提升路径处理可靠性
- 将 GUI 日志处理改为异步队列模式,避免 UI 阻塞
- 优化 ExcelProcessor 的表头识别逻辑,避免重复读取文件
- 更新配置文件中的版本号
This commit is contained in:
2026-03-30 11:17:25 +08:00
parent bfccdd3a37
commit b7bce93995
8 changed files with 101 additions and 46 deletions
+28
View File
@@ -219,6 +219,34 @@ def save_json(data: Any, file_path: str, ensure_ascii: bool = False, indent: int
logger.error(f"保存JSON文件失败: {file_path}, 错误: {e}")
return False
def smart_read_excel(file_path: Union[str, Path], **kwargs) -> Any:
"""
智能读取 Excel 文件,自动选择引擎并处理常见错误
Args:
file_path: Excel 文件路径
**kwargs: 传递给 pd.read_excel 的额外参数
Returns:
pandas.DataFrame 对象
"""
import pandas as pd
path_str = str(file_path)
ext = os.path.splitext(path_str)[1].lower()
# 自动选择引擎
if ext == '.xlsx':
kwargs.setdefault('engine', 'openpyxl')
elif ext == '.xls':
kwargs.setdefault('engine', 'xlrd')
try:
return pd.read_excel(path_str, **kwargs)
except Exception as e:
logger.error(f"读取 Excel 文件失败: {path_str}, 错误: {e}")
raise
def get_file_size(file_path: str) -> int:
"""
获取文件大小(字节)