Skip to content
Advertisement

How to Append a table with specified data from Google Spreadsheet to Google Doc using Google App Script? [duplicate]

As title, I’ve tried to append a table to Google Docs from Google Spreadsheet using GAS. So far, the post and some scripts I can find is about appending the whole sheet, not the selected or specified row or column. Below is the snippet. What should I do to make the snippet meet my need? Please advice.

p.s. the exception message: Exception: The parameters (number[]) don’t match the method signature for DocumentApp.Body.appendTable. would pop up after i execute the script.

JavaScript

Advertisement

Answer

Might I suggest you change your for loop as shown. I deleted the unused variables. 1st your need to construct rows just like Spreadsheet setValues() so I’ve enclosed the list of values within []. 2nd you already have the values so all these ss.getRange(i+1,3).getValue() are redundant and cause another call to the server. Remember column 3 is index 2 in the values array. So I’ve just used the values you got from getDataRange().getValues().

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement