问题描述
我尝试获取范围的值,然后从单元格中删除所有点.
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("Sheet1");
var A1 = CONTENT.getRange("I17").getValue();
A1. replace(".", "");
它让我找不到替换功能.Google Apps Script 中是否有任何函数可以让我替换字符串?
It gives me that can't find the replace function. Is there any function in Google Apps Script that allows me to replace the string?
推荐答案
如果这是您脚本的精确副本,那么您在 A1 之间有一个空格.
和 replace
但我认为它不是.
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 是正确的,内容需要是一个字符串,replace()
函数才能工作,所以如果你试图用十进制数替换 .
那么您可以先使用 toString()
方法,如下所示.
@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 :)
这篇关于如何使用 App Scripts 替换 Google 电子表格中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!