From 33ae440f6e3c96e432cd74567dc71ef60ddf266e Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Mon, 19 Jan 2026 17:31:07 +0800 Subject: [PATCH] fix: improve line handling in VBA code extraction to avoid extra blank lines --- extract_vba.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extract_vba.py b/extract_vba.py index e16ca66..a838b30 100644 --- a/extract_vba.py +++ b/extract_vba.py @@ -66,7 +66,10 @@ class VBAExtractor: (attributes_dict, clean_code) - 属性字典和清理后的代码 """ attributes = {} - lines = code.split('\n') + + # [修复] 使用 splitlines() 自动处理 \r\n,避免保留 \r 导致的多余空行 + lines = code.splitlines() + clean_lines = [] in_attributes = True @@ -87,7 +90,8 @@ class VBAExtractor: # 添加到清理后的代码(跳过空行和Attribute) if not in_attributes or (line.strip() and not line.strip().startswith('Attribute')): if not in_attributes: - clean_lines.append(line) + # 使用 rstrip() 去除行尾可能存在的空白符,保持代码整洁 + clean_lines.append(line.rstrip()) # 去除开头的空行 while clean_lines and not clean_lines[0].strip(): @@ -398,4 +402,4 @@ def main(): if __name__ == "__main__": - main() + main() \ No newline at end of file