From fec5ceed333056474320de5e5e78226cfbd0e241 Mon Sep 17 00:00:00 2001 From: HONOR Date: Wed, 16 Sep 2026 11:45:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20Temp=20=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E4=B8=8E=E5=8F=97=E4=BF=9D=E6=8A=A4=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E7=9A=84=E6=99=BA=E8=83=BD=E9=80=83=E9=80=B8?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/extractor.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/extractor.py b/src/core/extractor.py index e7e5974..f6130fd 100644 --- a/src/core/extractor.py +++ b/src/core/extractor.py @@ -43,10 +43,22 @@ def export_single_doc_tables(word_app, excel_app, doc_path, excel_path, log_func doc = None wb = None + file_to_clean = None try: if debug and log_func: log_func(f" [Debug] 正在调用 COM 接口打开文档: {abs_doc}") - doc = word_app.Documents.Open(FileName=abs_doc, ReadOnly=True, Visible=debug) + + try: + doc = word_app.Documents.Open(FileName=abs_doc, ReadOnly=True, Visible=debug) + except Exception as e: + if debug and 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)}") + shutil.copy2(abs_doc, file_to_clean) + doc = word_app.Documents.Open(FileName=file_to_clean, ReadOnly=True, Visible=debug) + table_count = doc.Tables.Count if table_count == 0: @@ -111,3 +123,8 @@ def export_single_doc_tables(word_app, excel_app, doc_path, excel_path, log_func doc.Close(SaveChanges=False) except Exception: pass + if file_to_clean and os.path.exists(file_to_clean): + try: + os.remove(file_to_clean) + except Exception: + pass