How to replace text in Google Spreadsheet using App Scripts?

前端 未结 4 1349
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 22:07

I tried to get the value of a range and than remove all points from the cell.

var FILE = SpreadsheetApp.openById(\"xyz\");
var CONTENT = FILE.getSheetByName(         


        
4条回答
  •  臣服心动
    2020-12-08 22:53

    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 :)

提交回复
热议问题