簡體   English   中英

以機器可讀格式獲取Google電子表格更改通知中更改的單元格的詳細信息

[英]Get details of cells changed from a Google Spreadsheet change notification in a machine readable format

如果我有Google電子表格,例如

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

我已經設置了通知,只要小區發生變化,就會立即給我發電子郵件。

我通過電子表格API對該電子表格進行了更改 - 即不是手動更改。

然后我收到這樣的電子郵件:

主題:最近編輯了“通知測試”

查看Google文檔“通知測試”中的更改:點擊此處

其他人從10/01/2014 12:23到12:23(格林威治標准時間)進行了更改

  • 價值改變了

如果我打開“點擊此處”鏈接,我會收到此網址,其中顯示了電子表格中已更改的單元格:

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修訂版: https//developers.google.com/drive/manage-revisions

我還嘗試使用Google Apps腳本設置onEdit()事件: https//developers.google.com/apps-script/understanding_triggers

我認為最后一種方法就是答案。

這種方法的問題在於雖然onEdit可用於通過電子郵件發送更改的詳細信息,但只有在手動編輯電子表格時才會觸發,而我的電子表格通過電子表格API以編程方式進行更新。

有任何想法嗎?

您可以構建一個檢查更改的函數。 一種方法是比較同一電子表格的多個實例。 如果存在差異,您可以給自己發送電子郵件。 使用時間驅動的觸發器,您可以檢查每分鍾,每小時,每天或每周(根據您的需要)。

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
    }
  }

然后從Resources> Current project的觸發器中,您可以將checkMatch設置為每分鍾運行一次。

另請查看https://developers.google.com/gdata/samples/spreadsheet_sample,以便將數據作為json提取

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM