I am using Google document a template for generating PDFs files. The template contains placeholders - **name-of-placeholder**
The placeholder is later on replaced with a value of corresponding variable. Now I need to replace a placeholder with a table.
Could someone suggest how to replace a text with a table using Google Application Script?
The template looks like that
I need to replace text detaily-programu with a table.
I managed to add a table
at the end of the document
// table method c.1
//Add a table in document
var table = body.appendTable()
at the point where is should be by replacing empty table
// table method c.2
// var searchType = DocumentApp.ElementType.TABLE
// var table = body.findElement(searchType).getElement()
// table.clear()
I would prefer to be able to replace the placeholder with a table. But I cannot make it work. .findText() finds the text but I do not know how to append the table after the element .findText() found. And of course delete the element.
// table method c.3
var text = body.findText("detaily-programu").getElement()
//var table = text.asParagraph().appendTable() // Exception: TEXT can't be cast to PARAGRAPH.
//var table = text.appendTable() // TypeError: text.appendTable is not a function