I was not able to solve the issue of adding multiple tables elegantly (It’s possible, but I don’t have the time right not).
But, you can copy the function exportDocsWithTable, add a copy of the parameters related to the table and the table generation loop, as in:
function exportDocsWithTable2(templateUrl, docTitle, userEmails, tableKey, tableKey2, columns, columns2, content)
…
// Make the content map
mapContent = Object.keys(columns[0]).map ( function (columnNumber) {
return columns.map( function (row) {
return row[columnNumber];
})
})
Logger.log("mapContent = " + mapContent);
// Make the second content map
mapContent2 = Object.keys(columns2[0]).map ( function (columnNumber) {
return columns2.map( function (row) {
return row[columnNumber];
})
})
…
// Add the rows to the table that matches the table key
var tables = body.getTables();
Logger.log("tables = " + tables);
Logger.log("tableKey = " + tableKey);
tables.forEach(table => {
Logger.log("table = " + table);
if(table.getCell(0,0).getText() == tableKey){
nr = table.getNumRows()
Logger.log("nr = " + nr);
for (key in mapContent){
tr = table.getChild(nr-1).copy();
Logger.log("tr = " + tr);
table.appendTableRow(tr)
Logger.log("mapContent[key].length = " + mapContent[key].length);
for (var j=0; j < mapContent[key].length; j++){
Logger.log("j = " + j);
tr.getChild(j).setText(mapContent[key][j]);
}
}
table.removeRow(nr-1)
}
})
// Add the rows to the second table that matches the table key
var tables = body.getTables();
Logger.log("tables = " + tables);
Logger.log("tableKey2 = " + tableKey2);
tables.forEach(table => {
Logger.log("table = " + table);
if(table.getCell(0,0).getText() == tableKey2){
nr = table.getNumRows()
Logger.log("nr = " + nr);
for (key in mapContent2){
tr = table.getChild(nr-1).copy();
Logger.log("tr = " + tr);
table.appendTableRow(tr)
Logger.log("mapContent2[key].length = " + mapContent2[key].length);
for (var j=0; j < mapContent2[key].length; j++){
Logger.log("j = " + j);
tr.getChild(j).setText(mapContent2[key][j]);
}
}
table.removeRow(nr-1)
}
})