report/main.py

24 lines
529 B
Python
Raw Permalink Normal View History

2023-07-31 13:49:34 +08:00
import json
import os
import sys
from docxtpl import DocxTemplate
from tools.parsexlsx import run
def main(path):
resjson = run(path)
res = json.loads(resjson)
barcode = res['c']['barcode']
tplpath = os.path.join(os.path.dirname(__file__), 'template', 'nreport.docx')
tpl = DocxTemplate(tplpath)
tpl.render(res)
path = os.path.join(os.path.dirname(__file__), 'result', f'{barcode}.docx')
tpl.save(path)
return path
if __name__ == '__main__':
2023-08-10 09:35:50 +08:00
main(sys.argv[1])