from docx import Document from docx.shared import Pt from pathlib import Path md_path = Path(r"C:\Users\ALC\.openclaw\workspace\analysis_report_content.md") out_path = Path(r"C:\Users\ALC\.openclaw\workspace\前后端功能与开源可修改性分析报告.docx") text = md_path.read_text(encoding='utf-8') doc = Document() style = doc.styles['Normal'] style.font.name = 'Microsoft YaHei' style.font.size = Pt(10.5) for line in text.splitlines(): if line.startswith('# '): doc.add_heading(line[2:].strip(), level=1) elif line.startswith('## '): doc.add_heading(line[3:].strip(), level=2) elif line.startswith('### '): doc.add_heading(line[4:].strip(), level=3) elif line.startswith('- '): doc.add_paragraph(line[2:].strip(), style='List Bullet') elif line.strip() == '---': doc.add_paragraph('') else: doc.add_paragraph(line) doc.save(out_path) print(str(out_path))