I have an apps script which takes email addresses from one spreadsheet from multiple cells and adds them them to another spreadsheet into 1 cell only. Currently the email addresses are added to that cell and separated by a ", ".
I would like to add the email addresses into that same cell but add a new line after each address.
I know it is possible to have new lines in a cell when manually adding text, by typing CTRL-Enter.
How can this be achieved in apps script?
I have so far tried to append "\n" or "\r" or "\r\n" to the string, to no avail, so I have reverted my code back to adding ", " instead.
sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.appendRow(["Num Emails", "Emails"]);
var LMEmails = "";
var count = 0;
for (var i = 0; i < reviewers.LMEmails.length; i++) {
if (count) {
LMEmails += ", " + reviewers.LMEmails[i];
} else {
LMEmails += reviewers.LMEmails[i];
}
count++;
}
data = [count, LMEmails];
sheet.appendRow(data);
If anyone could help, I would very much appreciate it
Regards Crouz
Manually add a new line in the same cell (Keyboard Shortcut)Double-click on the cell in which you want to add a line break (or select it and then press F2). Place the cursor where you want to insert the line break. Hold the ALT key and then press the Enter key (or Control + Option + Enter if you're using a Mac)
Just tap enter to start a new line and type your text in the second line. This way you can insert as many new lines as you want in your Google Sheets Android mobile app. It's very simple, right?
Thankfully, you can – to type information into more than one line in a Google Sheets cell, click on the cell in question and type the first line of your content in. Then, press Alt + Enter on your keyboard (or Option + Enter if you use a Mac) to get to a new line.
To insert a new line within a cell in Google Sheets, follow these steps: Type the text that you want to be on the first line within the cell. While the cell is still being edited, press Ctrl + Enter on the keyboard, and the cursor will go to a new line / a new line will be added within the same cell.
After searching for the same question, this was my solution:
var stringToDisplay = 'FirstBit' + String.fromCharCode(10) + 'SecondBit';
then
workSheet.getRange(1,1).setValue(stringToDisplay);
output will be in a single cell, :
FirstBit
SecondBit
Google Spreadsheets seems to ignore the new line if there are no characters after it.
Using "/n" works fine as long as you add at least one other character after it, this could be a space as shown below.
For example:
var myString = 'First Bit' + "\n " + "Second Bit";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With