2017-12-18 20 views
0

Google Docsのスクリプトに新しく、既存のスクリプトを使用して、 "検索と置換"機能にチェンジフォーマット機能を追加しました。たとえば、列Bを選択し、単語のすべてのインスタンスを検索し、「検索と置換」を使用して、単語を置き換えることができるだけでなく、書式を太字または斜体に変更する機能"Find and Replace"機能にチェンジフォーマット機能を追加するスクリプト

私は検索して自分で何かを見つけることができませんでしたので、誰かがスクリプトを知っていれば、それは非常に感謝しています。

もしそうでなければ、誰かがこのスクリプトを自分で作成することに関して、どこから始めるべきかのヒントを教えてください。

ありがとうございました。

答えて

1

このコードを使用すると、Googleドキュメントのテキストを検索して置き換えることができますが、の書式設定ののテキストを変更する必要があります。

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); 
} 
関連する問題