Python документ OpenOffice | генерировать шаблоныPython

Программы на Python
Anonymous
Python документ OpenOffice | генерировать шаблоны

Сообщение Anonymous »


Всем привет У меня специфичная (для меня ☺️) задача: необходимо сделать шаблон для Open Office. Я знаю как это можно сделать при помощи docxtpl библиотеки (DocxTemplate). Надеюсь мне кто-нибудь подскажет как в python можно работать с doc или как правильно сохранить docx в doc чтобы его открывал Open Office? Кусок моего кода 👇🏻

from docxtpl import DocxTemplate doc = DocxTemplate("template.docx") for i in patients: # переменная для замены в шаблоне context = {'patient': i, 'date': date.get()} doc.render(context) doc.save(path+ '/'+ i +".doc") Он работает, но когда я пытаюсь открыть *.doc в Open Office я. получаю ошибку о повреждённом файле. MS Office открывает его без проблем.

Hello everybody I have a specific (for me ☺️) task: need to make a template with Open Office. I know how it make with docxtpl library (DocxTemplate) I hope that anyone can explain me how python can work with doc or how I can save docx to doc for Open Office. my code 👇🏻

from docxtpl import DocxTemplate doc = DocxTemplate("template.docx") for i in patients: # data for replace context = {'patient': i, 'date': date.get()} doc.render(context) doc.save(path+ '/'+ i +".doc") It worked, but when I tried open with Open Office *.doc I take an error about damaged file. MS Word opened it without any problem.

Если я создаю *.docx, то потом не могу с ним работать, точнее я не могу его сохранить, Open Office может только читать docx. В общем я могу создать docx но не могу с ним работать или я могу создать doc но Open Office не может открыть его (я думаю, что мой код неверно сохраняет docx в doc т.к. если я сохраню doc через MS Office, то Open Office успешно его откроет).

If I created *.docx then I can't work with it more precisely I can't save it because Open Office can only reed docx. It turns out that I can create docx but can't work with it or I can make doc but Open Office can't open it (I think that my code wrong saving docx to doc, because if I save doc with MS Office Open Office successfully opened it).

Вернуться в «Python»