私はGoogleスクリプト内のテキストを置き換えることに取り組んできましたが、私が望むものは作成していません。現在私はここからキャメロンロバーツのスクリプト - How do I replace text in a spreadsheet with Google Apps Script?を使用していますが、私はそれを正しく取り上げていません。GoogleシートスクリプトのreplaceTextワイルドカード
このコードを使用して、 'values'という単語を '1'に置き換えようとしています。値を 'しかし、コードを複数回実行すると' 1 'が生成されます。 1.値 'etc'は 'values'文字列を見つけるだけです。私が望むのは、 '値'を検索し、次に '1'を入力するワイルドカードです。値を入力するだけですが、正規表現の構文を把握して修正できないようです。
function testReplaceInSheet(){
var sheet = SpreadsheetApp.getActiveSheet()
replaceInSheet(sheet,'values','1. values');
}
function replaceInSheet(sheet, to_replace, replace_with) {
//get the current data range values as an array
var values = sheet.getDataRange().getValues();
//loop over the rows in the array
for(var row in values){
//use Array.map to execute a replace call on each of the cells in the row.
var replaced_values = values[row].map(function(original_value){
return original_value.toString().replace(to_replace,replace_with);
});
//replace the original row values with the replaced values
values[row] = replaced_values;
}
//write the updated values to the sheet
sheet.getDataRange().setValues(values);
}
、 '1に起こっている理由です背後にある負の外観をシミュレートします。値 'には' values'が含まれていますので '1 'を残してください。 'は' 1 'になります。 1.値。何が起こってほしいですか?何もしない? –
返事をありがとう。私は '値'を '1'に置き換えたいと思います。値を 'しかし、明らかにこれが実行されるたびに、あなたが言うように、私は追加' 1。 '私は何をしたいのだろうと思うのは、'値 'が含まれている文字列全体が' 1 'に変わるだけです。値 'です。 – davey4444