From bd2365f2dd70673eca26b348e3f6986feadb0393 Mon Sep 17 00:00:00 2001 From: HONOR Date: Wed, 16 Sep 2026 11:47:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=B0=86=E5=85=8B=E9=9A=86?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E9=80=83=E9=80=B8=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E6=98=8E=E7=A1=AE=E6=8C=87=E5=AE=9A=E4=B8=BA=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E7=9B=AE=E5=BD=95=E4=B8=8B=E7=9A=84=20temp=20=E5=AD=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=B9=E5=B9=B6=E5=8A=A0=E5=85=A5=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E9=94=80=E6=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/extractor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/extractor.py b/src/core/extractor.py index f6130fd..5709705 100644 --- a/src/core/extractor.py +++ b/src/core/extractor.py @@ -55,7 +55,10 @@ def export_single_doc_tables(word_app, excel_app, doc_path, excel_path, log_func log_func(f" [Debug] 打开失败,疑似遇到受保护的视图拦截,尝试启动智能复制逃逸机制...") import shutil out_dir = os.path.dirname(abs_excel) - file_to_clean = os.path.join(out_dir, f"~temp_bypass_{os.path.basename(abs_doc)}") + temp_dir = os.path.join(out_dir, "temp") + if not os.path.exists(temp_dir): + os.makedirs(temp_dir, exist_ok=True) + file_to_clean = os.path.join(temp_dir, f"~temp_bypass_{os.path.basename(abs_doc)}") shutil.copy2(abs_doc, file_to_clean) doc = word_app.Documents.Open(FileName=file_to_clean, ReadOnly=True, Visible=debug) @@ -126,5 +129,8 @@ def export_single_doc_tables(word_app, excel_app, doc_path, excel_path, log_func if file_to_clean and os.path.exists(file_to_clean): try: os.remove(file_to_clean) + temp_dir = os.path.dirname(file_to_clean) + if not os.listdir(temp_dir): + os.rmdir(temp_dir) except Exception: pass