增加spire库生成word 测试
This commit is contained in:
parent
ee61bdf60c
commit
95c7522a1e
|
|
@ -73,8 +73,9 @@
|
||||||
<div id="section9" class="section">
|
<div id="section9" class="section">
|
||||||
<h2>图片展示</h2>
|
<h2>图片展示</h2>
|
||||||
{% for image in images %}
|
{% for image in images %}
|
||||||
<div class="image-container">
|
<!-- <div class="image-container"> -->
|
||||||
<img src="{{ image.src }}" alt="{{ image.alt }}">
|
<div style="text-align: center; margin-bottom: 10px;">
|
||||||
|
<img src="{{ image.src }}" alt="{{ image.alt }}" style="width: 200px; height: auto;">
|
||||||
<p>{{ image.caption }}</p>
|
<p>{{ image.caption }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -212,13 +212,15 @@
|
||||||
<div id="section9" class="section">
|
<div id="section9" class="section">
|
||||||
<h2>图片展示</h2>
|
<h2>图片展示</h2>
|
||||||
|
|
||||||
<div class="image-container">
|
<!-- <div class="image-container"> -->
|
||||||
<img src="/home/dengjinlai/ReportGeneration/PdfGeneration/input/image.png" alt="图片1">
|
<div style="text-align: center; margin-bottom: 10px;">
|
||||||
|
<img src="/home/dengjinlai/ReportGeneration/ReportGeneration/input/image.png" alt="图片1" style="width: 200px; height: auto;">
|
||||||
<p>这是一张示例图片1</p>
|
<p>这是一张示例图片1</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="image-container">
|
<!-- <div class="image-container"> -->
|
||||||
<img src="/home/dengjinlai/ReportGeneration/PdfGeneration/input/image.png" alt="图片2">
|
<div style="text-align: center; margin-bottom: 10px;">
|
||||||
|
<img src="/home/dengjinlai/ReportGeneration/ReportGeneration/input/image.png" alt="图片2" style="width: 200px; height: auto;">
|
||||||
<p>这是一张示例图片2</p>
|
<p>这是一张示例图片2</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -67,6 +67,14 @@ def html2docx(html_path, docx_path):
|
||||||
pypandoc.convert_file(html_path, 'docx', outputfile=docx_path)
|
pypandoc.convert_file(html_path, 'docx', outputfile=docx_path)
|
||||||
print("Word报告生成成功!")
|
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():
|
def main():
|
||||||
env = Environment(loader=FileSystemLoader(config.template_dir))
|
env = Environment(loader=FileSystemLoader(config.template_dir))
|
||||||
template = env.get_template("report_template.html")
|
template = env.get_template("report_template.html")
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,6 @@ pypandoc==1.13
|
||||||
pandas==2.2.2
|
pandas==2.2.2
|
||||||
opencv-python==4.10.0.84
|
opencv-python==4.10.0.84
|
||||||
openpyxl==3.1.4
|
openpyxl==3.1.4
|
||||||
Jinja2==3.1.4
|
Jinja2==3.1.4
|
||||||
|
|
||||||
|
#Spire.Doc==12.7.1
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -10,8 +10,16 @@ def resize_image(input_path, output_path, new_width=200):
|
||||||
new_height = int((float(height) * width_percent))
|
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)
|
cv2.imwrite(output_path, resized_img)
|
||||||
print(f"图片已保存为 {output_path}")
|
print(f"图片已保存为 {output_path}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
resize_image("./input/image.png","temp2.png")
|
||||||
|
|
||||||
Loading…
Reference in New Issue