Answer the question
In order to leave comments, you need to log in
Why is Docxtpl saving the wrong data?
The essence of the code is to take data from excel, and write it to word. It does everything right, but the data is still stored incorrectly.
Here is the full code:
import os
from docxtpl import DocxTemplate
from openpyxl import load_workbook
file = load_workbook(os.path.join(os.getcwd(), 'test.xlsx'))
data = file['Лист2']
doc = DocxTemplate("test.docx")
number = 2
count = 0
while count < 4:
value = data[f'C{number}'].value
if value:
count = 0
context = { 'kod_1' : str(data[f'A{number}'].value),
'kod_2' : str(data[f'B{number}'].value),
'last_name_ua': data[f'D{number}'].value,
'first_name_ua': data[f'E{number}'].value,
'last_name_en': data[f'F{number}'].value,
'first_name_en': data[f'G{number}'].value,
'date_of_birth': (str(data[f'H{number}'].value).replace('-', '/'))[:10],
'kod_3': str(data[f'C{number}'].value)}
doc.render(context)
doc.save(f"diplom/{data[f'D{number}'].value} {data[f'E{number}'].value}.docx")
print('Сделанно дипломов >>', (number-1), ', название: ',
f"{data[f'D{number}'].value} {data[f'E{number}'].value}.docx")
number += 1
count += 1
print('Работа выполнена')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question