How to replace text in Google Spreadsheet using App Scripts?

If this is an exact copy of your script then you have a space in-between A1. and replace but I assume it is not.

@SergeInsas is right the content needs to be a string for the replace() function to work, so if your trying to replace the . in a decimal number then you can use the toString() method first like below.

var FILE = SpreadsheetApp.openById("xyz");
var CONTENT = FILE.getSheetByName("Sheet1");
var A1 = CONTENT.getRange("I17").getValue();
var A1String = A1.toString().replace(".", "");

Or you can multiply the number to get rid of the decimal but this will depend on how many decimal places you have 🙂

Leave a Comment