Here we will learn how to create a table inside a Google document using Google apps script, This is a straightforward code which creates a table in Google Document.
We need to write a function. Likewise, I have created a function and called this createTable().
You can run this script by selecting function name createTable from the drop down and then click on play button as highlighted in Script in below image.
Moreover, it will create a table with blank values in each cell.
You can also apply styles to table cells. Rather, below code is applying light grey color to the cell, font bold, foreground color black and horizontal alignment left.
After adding this cell formatting code to create table function the entire code will look as below
Create Table On Google Doc from data on Google Spreadsheet
Firstly, Open source spreadsheet, you can use SpreadsheetApp.openById or SpreadsheetApp.openByUrl in script to open the sheet.
Secondly, you need to get the sheet which is having the source data, Suppose, source data is on the tab ‘TableData’ and range address A1: D10.