Answer the question
In order to leave comments, you need to log in
How to make dynamic substitution of parameters into a document in Google Docs via API?
The manager set the task: there are documents in Google Docs with placeholders like {{username}}, for which you need to make a wrapper in PHP.
The bottom line is this: when you click on a link on the project page, a document in RTF format should be generated and downloaded. Those. a request is made to the Google Docs API, the document is preloaded into memory, the necessary parameters are substituted, then it is issued to the user.
I tried to do it through an intermediate step: i.e. we download the document in html format, substitute the parameters through preg_replace, form a new document and send it for delivery through the PhpWord library. But the problem turned out to be that PhpWord cannot form a new dock normally and gives errors. Therefore, I hope that such operations can be done exclusively by means of the API.
Is it real? Please tell me who knows.
Answer the question
In order to leave comments, you need to log in
I did it differently. There is a docxtpl library in python. It is very easy to replace values in a dox file (like string formatting). Save new file and then send file to gdrive
php not for files =)
doc = DocxTemplate(path_to_template)
context = {
'theme': theme,
'regnumber': regnumber,
'address': address,
'date': date_created.strftime("%d.%m.%Y")
}
doc.render(context)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question