Merge pull request 'main' (#1) from main into v2025-07-11

Reviewed-on: #1
v2025-07-11
znsb2 7 days ago
commit 051a6743a4

Binary file not shown.

@ -3,12 +3,13 @@ import re
import os
import logging
import pandas as pd
from docx.oxml.ns import qn
from fastapi import HTTPException
from fastapi.responses import JSONResponse
from docx import Document
from pathlib import Path
from datetime import datetime
from docx.shared import Inches
from docx.shared import Inches, Pt
from app.tools.deal_excels import deal_excel, top5_dod_analysis, transform_data
from app.tools.get_time import get_time
from app.tools.replace_text import replace_text_in_docx
@ -740,6 +741,9 @@ def deal_docx(folder_path, save_path=None, time_type=0):
for paragraph in electricity_daily.paragraphs:
for run in paragraph.runs:
run.font.name = "Times New Roman"
#run.font.name = "仿宋"
#run._element.rPr.rFonts.set(qn('w:eastAsia'), '仿宋')
#run.font.size = Pt(16)
# 接口保存路径
electricity_daily.save(final_file)

@ -1,9 +1,12 @@
import logging
from docx.oxml.ns import qn
from docx.shared import Pt
# 获取日志记录器
logger = logging.getLogger(__name__)
#excluded_list = ['{{year}}','{{month}}', '{{day}}']
# 将文档中的字符串变量替换成提取内容
def replace_text_in_paragraph(paragraph, old_text, new_text):
try:
@ -12,7 +15,11 @@ def replace_text_in_paragraph(paragraph, old_text, new_text):
for run in paragraph.runs:
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}")
@ -25,7 +32,6 @@ def replace_text_in_docx(doc, replacements):
for paragraph in doc.paragraphs:
for old_text, new_text in replacements.items():
replace_text_in_paragraph(paragraph, old_text, new_text)
except Exception as e:
logger.exception(f"替换段落中的文本失败:{e}")
print(f"替换段落中的文本失败:{e}")

@ -22,6 +22,7 @@ def table_style(table):
for run in paragraph.runs:
# 设置英文字体(适用于数字和英文)
run.font.name = "Times New Roman"
#run.font.name = "仿宋"
# 设置中文字体
run._element.rPr.rFonts.set(qn("w:eastAsia"), "仿宋")
# 设置字体大小

Loading…
Cancel
Save