【发布时间】:2016-12-09 11:12:11
【问题描述】:
我正在尝试使用 Google 电子表格设置双向同步。我可以使用其Google Sheets API V4 将数据集中的更改推送到 Google 电子表格
现在,我希望能够在有人实时或近乎实时地进行编辑或添加新行时从 Google 电子表格中获取更新。
非常感谢任何为我指明正确方向的帮助。
【问题讨论】:
标签: google-apps-script google-sheets google-sheets-api
我正在尝试使用 Google 电子表格设置双向同步。我可以使用其Google Sheets API V4 将数据集中的更改推送到 Google 电子表格
现在,我希望能够在有人实时或近乎实时地进行编辑或添加新行时从 Google 电子表格中获取更新。
非常感谢任何为我指明正确方向的帮助。
【问题讨论】:
标签: google-apps-script google-sheets google-sheets-api
您可以通过转到工具-> 通知规则手动执行此操作..
如果文件在 Google Drive 中,您可以尝试使用Push Notifications: 要使用推送通知,您需要做三件事:
注册您的接收 URL 的域。例如,如果您打算 使用
//mydomain.com/notifications作为您的接收 URL,您需要 注册//mydomain.com。设置您的接收 URL,或“Webhook” 回调接收器。这是处理 API 的 HTTPS 服务器 资源更改时触发的通知消息。放 为您想要的每个资源端点建立一个通知通道 手表。通道指定通知的路由信息 消息。作为频道设置的一部分,您需要确定具体的 URL 您想在哪里接收通知。每当一个频道的资源 更改时,Drive API 会以 POST 请求的形式发送通知消息 到那个 URL。
谷歌演练video here。
您也可以使用 Appscript。这个简单的hack来自SO thread:
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
}
}
【讨论】: