

Otherwise, the new data will append the existing content. If you do this, you don’t have to select all and delete every time the script runs. One nice addition is to add a call to clear the data currently in the output document. It’s not a great solution, but it may help. You can also try using their logging command Logger.log() to help output data. Each table is a child of the document body. For this example, we created four tables (with no borders) to represent the four sections of the statement. To make things a little easier, you can put the content into tables. Google’s model of referencing elements in Google Docs along with the limited logging/debugging made this step the most challenging. It will add a page break so the next letter starts on the top of the next page. Before iterating to the next shareholder, the script will replace any custom variables created in the template. The script will then copy the body of the template once for each shareholder and paste it into the empty output document. I suggest creating a variable that is unlikely to have multiple instances in the content. For example, creating a variable like may be a good choice, because the script will perform a find-and-replace for the variable. Custom variables or placeholders will be added where the script should insert the content from the spreadsheet.Įach variable will be defined in the template and referenced in the script. This layout will be used for all shareholder letters. It will pull in data from the spreadsheet to access the shareholder names and number of shares for each shareholder, then lay out the shareholder statement.
#From google sheets to google doc merge code
A Google Script that will have the code to manage the data manipulationĪ Google Script will control all the data flow.


#From google sheets to google doc merge pdf
Instead of sending out custom emails to a group of recipients, we create a custom document or PDF in the same fashion. I like to think of it as mail merge for documents. Manually modifying numerous documents can be tedious. Google’s G Suite can help you make this process easier.
