Inserting a carriage return for data in a Google Spreadsheets/Docs

google-apps-script, google-docs, google-sheets

Solution

Edit: I found a way for it to work like this.

var sh11 = sh0.getRange('O2:O10').getValues()
var multiLine ="";

for (var i = 0; i <= sh11.length - 1; i++) 
{
multiLine += sh11[i]+"\n";
}

var d = DocumentApp.getActiveDocument();
var body = d.getBody();

body.replaceText('ThisText',multiLine);

Problem

I am trying to take some values from a google spreadsheet. Using a script, I would like to take each cell value and put a carriage return in after it, so that I can put them into a list form on a google doc. This is the code that I am using in my script. ``` var sh11 = sh0.getRange('O2:O10').getValues().forEach() + ",\n\n\"; ``` If I run it as it is written, I get the error message of "TypeError: (class)@2f0e9973 is not a function, it is undefined." If I modify it to this: ``` var sh11 = sh0.getRange('O2:O10').getValues().forEach(); ``` Then it runs, but clumps the output all together, like this example. If my column values are this: ``` O2 Waffles O3 Pancakes O4 Eggs O5 Toast ``` I am getting Waffles, Pancakes, Eggs, Toast as the output. I would like the doc to look like this: ``` Waffles Pancakes Eggs Toast ``` Any help would be greatly appreciated. Thank you, Paul

Original source