diff --git a/app/templates/日报模板.docx b/app/templates/日报模板.docx index 186a260..947507b 100644 Binary files a/app/templates/日报模板.docx and b/app/templates/日报模板.docx differ diff --git a/app/templates/简报模板.docx b/app/templates/简报模板.docx index 49d2e5c..edbfb49 100644 Binary files a/app/templates/简报模板.docx and b/app/templates/简报模板.docx differ diff --git a/app/tools/replace_text.py b/app/tools/replace_text.py index 1667dfe..34c1d15 100644 --- a/app/tools/replace_text.py +++ b/app/tools/replace_text.py @@ -42,6 +42,7 @@ def replace_text_in_paragraph(paragraph, old_text, new_text): if old_text in paragraph.text: # 检查段落中是否存在模板字符串 # 遍历段落的每个运行 for run in paragraph.runs: + """ if old_text =="{{sentiment_trend}}": print("定制化加粗") if old_text in run.text: @@ -50,19 +51,24 @@ def replace_text_in_paragraph(paragraph, old_text, new_text): paragraph.add_run(before) target_run = paragraph.add_run(new_text) paragraph.add_run(after) + before.font.name = "Times New Roman" + before._element.rPr.rFonts.set(qn('w:eastAsia'), '仿宋') + before.font.size = Pt(16) if old_text == "{{sentiment_trend}}": target_run.bold = True target_run.font.name = "Times New Roman" target_run._element.rPr.rFonts.set(qn('w:eastAsia'), '仿宋') target_run.font.size = Pt(16) + else: - if old_text in run.text: - run.text = run.text.replace(old_text, new_text) - if old_text.startswith('{{') : - run.font.name = "Times New Roman" - #run.font.name = "仿宋" - run._element.rPr.rFonts.set(qn('w:eastAsia'), '仿宋') - run.font.size = Pt(16) + """ + if old_text in run.text: + run.text = run.text.replace(old_text, new_text) + if old_text.startswith('{{') : + run.font.name = "Times New Roman" + #run.font.name = "仿宋" + run._element.rPr.rFonts.set(qn('w:eastAsia'), '仿宋') + run.font.size = Pt(16) except Exception as e: logger.exception(f"替换段落里的文本失败:{e}") print(f"替换段落里的文本失败:{e}")