[英]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.'); } }
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(您将在第一个示例代码中添加的那个)
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 手动测试它
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.