feat: base 增加docxtpl导出函数

This commit is contained in:
caoqianming 2023-10-30 09:50:02 +08:00
parent 388ddd96ba
commit 0017d8b729
2 changed files with 18 additions and 0 deletions

View File

@ -6,6 +6,23 @@ from datetime import datetime
from openpyxl import Workbook, styles
from openpyxl.drawing.image import Image
from openpyxl.utils import get_column_letter, column_index_from_string
from docxtpl import DocxTemplate
def export_docx(template_path: str, context_data: dict, file_name: str):
"""
Word导出
:param template_path: 模板路径
:param context_data: 数据
:param file_name: 保存的文件名
:return:返回文件路径
"""
docx = DocxTemplate(settings.BASE_DIR + template_path)
docx.render(context_data)
file_path = f'/media/temp/{file_name}'
save_path = settings.BASE_DIR + file_path
docx.save(save_path)
return file_path
def len_byte(value):

View File

@ -31,4 +31,5 @@ openpyxl==3.1.0
cron-descriptor==1.2.35
pymysql==1.0.3
face-recognition==1.3.0
docxtpl==0.16.7
# deepface==0.0.79