Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 714
Stretch Avatar asked Apr 19 '26 09:04

Stretch


1 Answers

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);
like image 129
nwill001 Avatar answered Apr 23 '26 19:04

nwill001



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!