testing123
testing123

Reputation: 831

google apps script get string values of cell with formula

Anyone know of a way to get the plain text value of a cell that is outputted with a formula using google apps scripts? e.g. I have FName and LName columns. I've concatenated the columns into FullName. I would like to copy the FullName column values to another column. I just want to copy the string value of FullName not the formula it was outputted with.

Upvotes: 3

Views: 7003

Answers (1)

user6655984
user6655984

Reputation:

Use copyTo method with the option contentsOnly: true. Its effect is equivalent to Ctrl-C followed by Ctrl-Shift-V (paste values) in the spreadsheet interface. Example:

var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("F:F"); 
var target = sheet.getRange("J:J");
range.copyTo(target, {contentsOnly: true});

(Another way is to use getValues followed by setValues, but copyTo does both things at once.)

Upvotes: 1

Related Questions