简体   繁体   English

如何在 Google 表格中获取所有版本的数据?

[英]How to get All versions' data in Google sheet?

I have a Google sheet which has a large number of versions.我有一个包含大量版本的 Google 表格。 Now, I want to get each version one by one, extract data of that version into Google sheet.现在,我想一个一个地获取每个版本,将该版本的数据提取到 Google 表格中。 I have tried to follow the below solution from @Tanaike:我试图遵循@Tanaike 的以下解决方案:

function myFunction() {
  var spreadsheetId = "###"; // Please set the Spreadsheet ID.
  var revisionId = "###"; // Please set the revision ID.

  var url = "https://docs.google.com/spreadsheets/export?id=" + spreadsheetId + "&revision=" + revisionId + "&exportFormat=xlsx";
  var blob = UrlFetchApp.fetch(url, {headers: {Authorization: "Bearer " + ScriptApp.getOAuthToken()}}).getBlob();
  var id = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS, title: revisionId}, blob).id;


  var spreadsheet = SpreadsheetApp.openById(id);
  var sheet = spreadsheet.getSheets()[0];
  var sheetdata = sheet.getDataRange().getValues();
}

It would be helpful if you can guide me/suggest it to me about it.如果你能指导我/向我建议它,那将会很有帮助。 I just want to get all the data for each version history and put it into Google sheets.我只想获取每个版本历史记录的所有数据并将其放入 Google 表格中。 Thank you for your guidance.谢谢你的指导。

Following the advice in the comments.按照评论中的建议。 The sample code requires the revision ID.示例代码需要修订 ID。 A sample code to gather all the revisions ID:收集所有修订 ID 的示例代码:

 function listRevisions(fileId) { var fileId = 'yourfileid'; var revisions = Drive.Revisions.list(fileId); if (revisions.items && revisions.items.length > 0) { for (var i = 0; i < revisions.items.length; i++) { var revision = revisions.items[i]; var date = new Date(revision.modifiedDate); Logger.log(revision.id); } } else { Logger.log('No revisions found.'); } }

  1. Get the File ID of the Spreadsheet that you want to get its revision (the one you would be adding in the first sample code)获取您想要修改的电子表格的文件 ID(您将在第一个示例代码中添加的那个)

  2. Revisions: list , you can get here the list of all revision that you do for that file in particular and is presented in the sample code above or you can manually test it over the web Revisions: list ,您可以在此处获得您对该文件所做的所有修订的列表,并在上面的示例代码中显示,或者您可以通过 web 手动测试它

  3. By using Revisions: get , you should be able to get an specific revision details of the file by adding both the file id and revision id.通过使用Revisions: get ,您应该能够通过添加文件 ID 和修订 ID 来获取文件的特定修订详细信息。

There is also an excellent thread with information about it where the sample code was taken (besides the ones linked in the revision list official documentation, there are javascript samples that can also be used) feel free to review the thread还有一个很好的线程,其中包含有关示例代码的信息(除了修订列表官方文档中链接的那些之外,还有 javascript 个样本也可以使用)随时查看线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取旧版本的 Google 电子表格数据? - How to get older versions of Google Spreadsheet data? 如何将工作表中的所有数据转换为值-Google电子表格 - How to transform all data in sheet to values - google spreadsheets 如何从Google表格获取数据到我的Gmail插件 - How to get data from google sheet to my Gmail addon 将 Google 工作表数据一次全部导入到现有工作表中 - Import Google Sheet Data all at once to an existing sheet with data 如何从Google Sheet数组的数据数组中获取lastRow? - How to get lastRow from array of data from Google Sheet array? 如何从Google表格获取数据以在已部署的Web应用程序中使用 - How to get data from Google Sheet to use in deployed web app 如何使用 Google App Script 将一个 Google Sheet 中的所有数据提取到另一个 Google Sheet Tab? - How do I pull All data in one Google Sheet to another Google Sheet Tab using Google App Script? 从 Google 表格中的 1 URL 获取所有数据 - Fetch All Data from 1 URL in Google Sheet 使用Google Apps脚本获取工作表中包含数据的特定行为空的所有行 - get all rows in a sheet with data where a specific column is empty using Google Apps Scripts 如何使用应用程序脚本谷歌驱动器从谷歌表中的父文件夹中获取所有子文件夹名称 - How to get list all sub folders name from parent folders in google sheet with apps script google drive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM