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