diff --git a/input/report_template.html b/input/report_template.html index 43a8e7b..e56a479 100644 --- a/input/report_template.html +++ b/input/report_template.html @@ -73,8 +73,9 @@

图片展示

{% for image in images %} -
- {{ image.alt }} + +
+ {{ image.alt }}

{{ image.caption }}

{% endfor %} diff --git a/output/generated_report.docx b/output/generated_report.docx index e8774d6..a705894 100644 Binary files a/output/generated_report.docx and b/output/generated_report.docx differ diff --git a/output/generated_report.html b/output/generated_report.html index 79b496d..97cf608 100644 --- a/output/generated_report.html +++ b/output/generated_report.html @@ -212,13 +212,15 @@

图片展示

-
- 图片1 + +
+ 图片1

这是一张示例图片1

-
- 图片2 + +
+ 图片2

这是一张示例图片2

diff --git a/output/generated_report.pdf b/output/generated_report.pdf index 4118c10..84dea22 100644 Binary files a/output/generated_report.pdf and b/output/generated_report.pdf differ diff --git a/report_generation.py b/report_generation.py index 32c4d0e..2553cc1 100644 --- a/report_generation.py +++ b/report_generation.py @@ -67,6 +67,14 @@ def html2docx(html_path, docx_path): pypandoc.convert_file(html_path, 'docx', outputfile=docx_path) print("Word报告生成成功!") +def html2docx_spire(html_path, docx_path): + from spire.doc import FileFormat,XHTMLValidationType,Document + # from spire.doc.common import * + document = Document() + document.LoadFromFile(html_path, FileFormat.Html, XHTMLValidationType.none) + document.SaveToFile(docx_path, FileFormat.Docx2016) + document.Close() + def main(): env = Environment(loader=FileSystemLoader(config.template_dir)) template = env.get_template("report_template.html") diff --git a/requirements.txt b/requirements.txt index 6318b45..805702e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,6 @@ pypandoc==1.13 pandas==2.2.2 opencv-python==4.10.0.84 openpyxl==3.1.4 -Jinja2==3.1.4 \ No newline at end of file +Jinja2==3.1.4 + +#Spire.Doc==12.7.1 \ No newline at end of file diff --git a/test_files/test_spire.py b/test_files/test_spire.py new file mode 100644 index 0000000..f72e71f --- /dev/null +++ b/test_files/test_spire.py @@ -0,0 +1,12 @@ +from spire.doc import FileFormat,XHTMLValidationType,Document +# from spire.doc.common import * + +# 创建Document类的对象 +document = Document() + +# 加载一个HTML文件 +document.LoadFromFile("output/generated_report.html", FileFormat.Html, XHTMLValidationType.none) + +# 将HTML文件保存为.docx格式 +document.SaveToFile("Html文件转为Word2.docx", FileFormat.Docx2016) +document.Close() \ No newline at end of file diff --git a/utils/cv_tools.py b/utils/cv_tools.py index a787a17..74e6763 100644 --- a/utils/cv_tools.py +++ b/utils/cv_tools.py @@ -10,8 +10,16 @@ def resize_image(input_path, output_path, new_width=200): new_height = int((float(height) * width_percent)) # 调整图片大小 - resized_img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_LANCZOS4) - + # resized_img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_LANCZOS4) + resized_img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_AREA) + # 保存调整后的图片 cv2.imwrite(output_path, resized_img) print(f"图片已保存为 {output_path}") + + + + +if __name__ == "__main__": + resize_image("./input/image.png","temp2.png") + \ No newline at end of file