为什么我的脚本不起作用?它不搜索数据。消息显示已完成,但床单看起来没有变化。我可以帮助谁?
function SearchReplaceInFormula() { //begin work
var pattern = Browser.inputBox("Enter the search string:"); //text on label
var replacement = Browser.inputBox("Enter the replacement string:"); //text on label
if (pattern == "" && replacement == "") // empty
{
Browser.msgBox("Nothing to search and or replace");
return;
}
//
var formula = SpreadsheetApp.getActiveRange().getValues(); //get a data all range
var range = SpreadsheetApp.getActiveRange(); //get range
var crows = range.getNumRows(); //last rows
var ccols = range.getNumColumns(); //last columns
var row = 0; //
for (row = 1; row <= crows; row++)//
{
for (col=1; col <= ccols; col++) //
{
var cell = range.getCell(row, col);
var formula = cell.getValues(); //may be getValue
var updated = formula; //update
while(-1 != updated.indexOf(pattern)) //what -1
{
updated = updated.replace(pattern, replacement); //replace before update
}
if (formula != updated)
{
cell.setFormula(updated) //set vales?
}
}
}
Browser.msgBox("Done replacing " + pattern + " with " + replacement); //shows always
}