feat: base 增加docxtpl导出函数
This commit is contained in:
parent
388ddd96ba
commit
0017d8b729
|
@ -6,6 +6,23 @@ from datetime import datetime
|
||||||
from openpyxl import Workbook, styles
|
from openpyxl import Workbook, styles
|
||||||
from openpyxl.drawing.image import Image
|
from openpyxl.drawing.image import Image
|
||||||
from openpyxl.utils import get_column_letter, column_index_from_string
|
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):
|
def len_byte(value):
|
||||||
|
|
|
@ -31,4 +31,5 @@ openpyxl==3.1.0
|
||||||
cron-descriptor==1.2.35
|
cron-descriptor==1.2.35
|
||||||
pymysql==1.0.3
|
pymysql==1.0.3
|
||||||
face-recognition==1.3.0
|
face-recognition==1.3.0
|
||||||
|
docxtpl==0.16.7
|
||||||
# deepface==0.0.79
|
# deepface==0.0.79
|
||||||
|
|
Loading…
Reference in New Issue