2016-10-19 5 views
0

Googleキャッシュサービスを使用して値を保存しようとしていますが、増分していないようです。Googleスプレッドシートキャッシュサービスに保存された値を増やす

//Starts a new instance of cache 
    var cache = CacheService.getScriptCache(); 
    //Puts the value 2 into foo key of Cache 
    cache.put('foo', 2); 
    //Grabs that value 
    var startMessageRow = cache.get('foo'); 
    //stuff for an email I'm sending using this cached value 
    var messageDataRange = sheet.getRange(startMessageRow, 2) 
    var message = messageDataRange.getValues(); 
    //Here's where I'm trying to increment it, but the value is staying at 2 
    cache.put('foo','startMessageRow'+1); 

私はしかし、値がちょうど関係なく、私がしようとするもの2で立ち往生されていない、1でこのスクリプトを実行するたびに値をインクリメントしようとしている場所のコードの最後の行である - ここでは、コードです。

答えて

0

これを行う簡単な方法が見つかりました。私はちょうどランダムなセルにカウンタを入れて、スクリプトを実行するたびにその値に1を加えます。キャッシュサービスを使用するより簡単に!

var cellRange = s1.getRange("W726"); //set this string to be the corresponding cell for daily counter 
    var cell = cellRange.getValues(); //grabs the value from that cell 
    var startMessageRow = cell; //sets StartMessage Row to be equal to the value of counter 
    startMessageRow = parseInt(startMessageRow);//ints it 

    cell = parseInt(cell); //ints it 
    cell+=1; //increments 
    cell = cell+""; // strings it 
    cellRange.setValue(cell); // puts the new value in 
関連する問題