I'm writing a merging program. Instead of creating one document per input row, I want the merged (template with input values replaced) output from each input row added to a single document.
And the template is not just text. It's another Google doc with a standalone table.
I started with the mail merge example and it works fine but produces a separate doc for each input row. I've written a helper function that I call for each output doc, with "dest_doc" set to my summary doc.
Sadly, this does not work since the API seems only to permit unstyled text insertion, not contents-from-a-Doc.
It works fine when using 'hello world '
-- this is properly replicated in the output file. But when I replace it with body
or body['contents']
it fails.
Is there any way of doing this? I'd balk at writing a contents-tree-to-UpdateRequest translator.
def append_contents(dest_doc, source_doc):
"""Copy the contents of the source doc to the end of the destination doc
"""
document = DOCS.documents().get(documentId=source_doc).execute()
body = document.get('body')
requests = [
{
'insertText': {
'endOfSegmentLocation': {
'segmentId': '',
},
'text': 'hello world '
}
},
]
DOCS.documents().batchUpdate(documentId=dest_doc, body={'requests': requests}).execute()
return
Thanks for your time.