fix: improve line handling in VBA code extraction to avoid extra blank lines

This commit is contained in:
Misaka_Company
2026-01-19 17:31:07 +08:00
parent c80e03e1ea
commit 33ae440f6e

View File

@@ -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()