从 Google 电子表格接收实时更新
Receive real time updates from a Google Spreadsheet
我正在尝试使用 Google 电子表格设置双向同步。我可以使用 Google Sheets API V4
将数据集中的更改推送到 Google 电子表格
现在,我希望能够在有人实时或近乎实时地编辑或添加新行时从 Google 电子表格中获取更新。
非常感谢为我指明正确方向的任何帮助。
您可以通过转到工具-> 通知规则手动执行此操作..
如果文件在Google盘,你可以尝试使用Push Notifications:
要使用推送通知,您需要做三件事:
Register the domain of your receiving URL. For example, if you plan to
use //mydomain.com/notifications
as your receiving URL, you need to
register //mydomain.com
. Set up your receiving URL, or "Webhook"
callback receiver. This is an HTTPS server that handles the API
notification messages that are triggered when a resource changes. Set
up a notification channel for each resource endpoint you want to
watch. A channel specifies routing information for notification
messages. As part of the channel setup, you identify the specific URL
where you want to receive notifications. Whenever a channel's resource
changes, the Drive API sends a notification message as a POST request
to that URL.
Google 演练 video here.
您也可以使用 Appscript。这个简单的技巧来自 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
}
}
我正在尝试使用 Google 电子表格设置双向同步。我可以使用 Google Sheets API V4
将数据集中的更改推送到 Google 电子表格现在,我希望能够在有人实时或近乎实时地编辑或添加新行时从 Google 电子表格中获取更新。
非常感谢为我指明正确方向的任何帮助。
您可以通过转到工具-> 通知规则手动执行此操作..
如果文件在Google盘,你可以尝试使用Push Notifications: 要使用推送通知,您需要做三件事:
Register the domain of your receiving URL. For example, if you plan to use
//mydomain.com/notifications
as your receiving URL, you need to register//mydomain.com
. Set up your receiving URL, or "Webhook" callback receiver. This is an HTTPS server that handles the API notification messages that are triggered when a resource changes. Set up a notification channel for each resource endpoint you want to watch. A channel specifies routing information for notification messages. As part of the channel setup, you identify the specific URL where you want to receive notifications. Whenever a channel's resource changes, the Drive API sends a notification message as a POST request to that URL.
Google 演练 video here.
您也可以使用 Appscript。这个简单的技巧来自 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
}
}