如何从Google表格获取修改后的内容? [英] How to get the modified content from google sheets?

查看:119
本文介绍了如何从Google表格获取修改后的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定的时间之后,我正在尝试从Google表格获取修改后的内容.我在任何地方都找不到可以获取数据的api.我看到的是仅从驱动器Api获得修改日期.如何使用Drive或Sheets Api获得数据?请给我建议

I am trying to get the modified content after the given time from google sheets. Nowhere I can found the api to get the data. What i can see is getting modified date alone from the drive Api. How can I get the data using Drive or Sheets Api? Give me the suggestions if Possible

推荐答案

Google云端硬盘会跟踪其中包含的文件的修订历史记录.但是,无法仅从请求中获取修订.

Google Drive keeps a track of revision history of files that are contained on it. There is however, no way to obtain the revisions from a request alone.

Google允许您每当用户对电子邮件通知进行接收您的工作表,可以通过完成以下步骤进行设置:

Google allows for you to receive email notifications whenever a user makes an edit to your sheet, which you can set up by completing the following steps:

  1. 在电子表格的网络视图中,单击Tools -> Notification rules...
  2. Notify me at myemail@address.ext when...下选择Any changes are made
  3. Notify me with...下选择Email - right away
  4. 单击Save.
  1. In the Spreadsheet's web view, click Tools -> Notification rules...
  2. Under Notify me at myemail@address.ext when... select Any changes are made
  3. Under Notify me with... select Email - right away
  4. Click Save.

您还应该注意,您不会收到有关您对工作表所做的编辑的通知-仅当其他用户编辑工作表时才会收到通知.每当收到电子邮件通知时,您都会收到一个链接,以只读Web视图链接的形式查看对电子表格所做的更改.

You should also be aware that you will not get a notification for edits made to the sheet by you - notifications are only received when another user edits the sheet. Whenever you get an email notification, you will receive a link to view the changes to the spreadsheet in the form of a read-only web view link.

您可以以编程方式解决此问题,尽管没有一种正确的方法,而且可能非常复杂.您可以使用Drive REST API的 Revisions: list方法以获得有关进行编辑的用户的信息,以及可用于

You can work around this programatically, though there isn't one right way and it can be quite complicated. You can use the Revisions: list method of the Drive REST API to get the information about the user that made an edit, as well as a list of links which you can use to export that revision of the sheet to another MIME Type, as shown below in the request response.

请求:

GET https://www.googleapis.com/drive/v3/files/SPREADSHEET_ID/revisions

,以revisions/exportLinks,revisions/lastModifyingUser/emailAddress作为fields字段,并将SPREADSHEET_ID替换为电子表格的ID将为您提供200响应:

with revisions/exportLinks,revisions/lastModifyingUser/emailAddress as the fields field and replacing SPREADSHEET_ID with the ID of the spreadsheet will give you a 200 response:

{
 "revisions": [
  {
   "lastModifyingUser": {
    "emailAddress": "username@domain.ext"
   },
   "exportLinks": {
    "application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=revisionNumber&exportFormat=ods",
    "text/tab-separated-values": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=revisionNumber&exportFormat=tsv",
    "application/pdf": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=revisionNumber&exportFormat=pdf",
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=revisionNumber&exportFormat=xlsx",
    "text/csv": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=revisionNumber&exportFormat=csv",
    "application/zip": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=revisionNumber&exportFormat=zip",
    "application/vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=SPREADSHEET_ID&revision=1&exportFormat=ods"
   }
  }
 ]
}

通过指向各个更改的链接,您可以使用Apps脚本获取和比较工作表的不同版本,并输出版本之间具有不同值的单元格的A1表示法.使用原始Revisions: list请求中的电子邮件地址,这足以编译文件或包含的日志.

With the links to individual changes, you can fetch and compare the different versions of the Sheet using Apps Script, and output A1 notation of the cells that have different values between versions. This, with the email address from the original Revisions: list request, is enough to compile a file or a log containing.

您可以将其放入简单的onEdit()触发器绑定到工作表将使您每次用户编辑工作表时自动获取更改.

You can put this into a simple onEdit() trigger bound to the sheet will allow you to automatically get the changes each time a user edits the sheet.

这篇关于如何从Google表格获取修改后的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆