4

たとえばGoogleスプレッドシートがある場合

https://docs.google.com/spreadsheet/ccc?key=0AjAdgux-AqYvdE01Ni1pSTJuZm5YVkJIbl9hZ21PN2c&usp=sharing

また、セルが変更されるたびにすぐにメールで通知するように設定しました。

そして、スプレッドシート API を介してそのスプレッドシートに変更を加えます。つまり、手作業ではありません。

すると、次のようなメールが届きます。

件名: 「通知テスト」は最近編集されました

Googleドキュメントの「通知テスト」で変更を確認してください: ここをクリック

他の人が 2014 年 10 月 1 日 12:23 から 12:23 (グリニッジ標準時) に変更しました

  • 値が変更されました

「ここをクリック」リンクを開くと、スプレッドシートで変更されたセルを示す次の URL が表示されます。

https://docs.google.com/a/DOMAINGOESHERE/spreadsheet/ver?key=tn9EJJrk6KnJrAEFaHI8E3w&t=1389356641198000&pt=1389356621198000&diffWidget=true&s=AJVazbUOm5tHikrxX-bQ0oK_XEapjEUb-g

私の質問は:

どのセルが変更されたかに関する情報を、プログラムで操作できる形式 (JSON など) で取得する方法はありますか?

Google スプレッドシート API を確認しました: https://developers.google.com/google-apps/spreadsheets/

Drive API Revisions: https://developers.google.com/drive/manage-revisions

また、Google Apps Script を使用して onEdit() イベントを設定しようとしました: https://developers.google.com/apps-script/understanding_triggers

この最後のアプローチが答えになると思いました。

このアプローチの問題は、onEdit を使用して変更の詳細を電子メールで送信できる一方で、スプレッドシートが手動で編集された場合にのみ起動されるように見えることです。

何か案は?

4

1 に答える 1

5

変更をチェックする関数を作成できます。これを行う 1 つの方法は、同じスプレッドシートの複数のインスタンスを比較することです。違いがある場合は、自分自身に電子メールを送信できます。時間駆動トリガーを使用すると、必要に応じて、毎分、毎時、日、または週を確認できます。

var sheet = **whatever**;//The spreadsheet where you will be making changes
var range = **whatever**;//The range that you will be checking for changes
var compSheet = **whatever**;//The sheet that you will compare with for changes
function checkMatch(){
  var myCurrent = sheet.getRange(range).getValues();
  var myComparison = compSheet.getRange(range).getvalues();
  if(myCurrent == myComparison){//Checks to see if there are any differences
    for(i=0;i<compSheet.length;++i){ //Since getValues returns a 'multi-dimensional' array, 2 for loops are used to compare each element
     for(j=0;j<compSheet[i].length;++i){
      if(myCurrent[i][j] != myComparison[i][j]){//Determines if there is a difference;
       //***Whatever you want to do with the differences, put them here***
     }
    }

    myEmailer(sheet.getUrl());//Passes the url of sheet to youur emailer function 
    compSheet.getRange(range).setValues(myCurrent);//Updates compSheet so that next time is can check for the next series of changes
    }
  }

次に、[リソース] > [現在のプロジェクトのトリガー] から、 checkMatchを毎分実行するように設定できます。

https://developers.google.com/gdata/samples/spreadsheet_sampleもチェックして、json としてデータを取得してください

于 2014-03-31T15:26:41.163 に答える