LANG SELRCT

Apps Script Reference  (Create: Create new Spreadsheet | Create new Apps Script

Sunday, June 10, 2018

ScriptPropertiesを読み書きしてみる


ScriptPropertiesを読み書きして

こういうデータを保存して取得してみる

 {key1=hello, key2=world}



コード.gs
var ScriptProperties = PropertiesService.getScriptProperties();

function myFunction(){
  var value1 = "hello";
  var value2 = "world";
  set_property("key1", value1);
  set_property("key2", value2);  
  Logger.log(get_properties());
}

function set_property(key, value){
  ScriptProperties.setProperty(key, value); 
}

function get_properties() {
  return ScriptProperties.getProperties();
}

function delete_properties() {
  ScriptProperties.deleteAllProperties();
}


set_properties()でScriptPropertiesに保存する
get_properties()で保存されているScriptPropertiesを取得する
delete_properties()でScriptPropertiesの中身を削除できる


実行結果

myFunction()を実行したログ



参考

Class PropertiesService
https://developers.google.com/apps-script/reference/properties/properties-service

Latest post

Extracting data from Google Sheets with regular expressions

Introduction Regular expressions are a powerful tool that can be used to extract data from text.  In Google Sheets, regular expressions ca...