gpt4 book ai didi

email - 以机器可读的格式从 Google 电子表格更改通知中获取更改的单元格的详细信息

转载 作者:行者123 更新时间:2023-12-01 01:03:25 24 4
gpt4 key购买 nike

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

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

我已经在上面设置了通知,以便在单元格发生变化时立即给我发送电子邮件。

我通过电子表格 API 对该电子表格进行了更改 - 即不是手动更改。

然后我收到一封这样的电子邮件:

Subject: "Notification Test" was edited recently

See the changes in your Google Document "Notification Test": Click here

other person made changes from 10/01/2014 12:23 to 12:23 (Greenwich Mean Time)

  • Values changed


如果我打开“单击此处”链接,则会得到此 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 修订版中:
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
}
}

然后来自 资源>当前项目的触发器您可以设置 checkMatch 每分钟运行一次。

另请查看 https://developers.google.com/gdata/samples/spreadsheet_sample用于将数据提取为 json

关于email - 以机器可读的格式从 Google 电子表格更改通知中获取更改的单元格的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21044661/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com