Question

I am trying to use a line break in Google Sheets. If I want a cell to show this:

Over
Under


What do I put inside the set.Value() method?

I am trying this:

function myFunction(cell){
  cell.setValue('Over
                 Under')
  }

Does not work....

UPDATE: I have also tried this

cell.setValue(otherCell.getValue());

This seems to work as long as otherCell is the value I want. I can't figure out how to inspect this element though.

Was it helpful?

Solution

I've been using "\n", to insert a new line into a text cell.

and example would be:

cell.setValue("Over"+"\n"+"Under");

Yields:

Over
Under

It works pretty well for situations where you are appending the contents of a cell:

cell.setValue(cell.getValue()+"\n"+"Updated info");

OTHER TIPS

I figured it out by using String.charCodeAt(), it seems that the 'line break' has a unicode value of 10.

cell.setValue('Over'+String.fromCharCode(10)+'Under') 

yields a single cell with

Over
Under


Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top