简体   繁体   中英

How to access revision history of a spreadsheet using GAS?

Is it possible to access revision history data of a spreadsheet directly from Google Apps Scripts? If so, how?

I would like to do two things:

  1. Change the username logged for each revision to the actual user running the script and not the script author/owner. As I've just learned, revision history of a spreadsheet that's accessed and modified using GAS always reflects the script owner/author instead of the user running the script.

If the above is not possible, then

  1. Get direct read access to revision number and username in the history straight from GAS. From there, I'll just do a comparison table and hope for the best that I'll achieve the same effect.

I don't believe it's possible to access the revision history with Apps Script. There is an open feature request for this ability though, and if you star it you'll receive an email when there is an update:

http://code.google.com/p/google-apps-script-issues/issues/detail?id=394

It's not possible to change data from the revision history.

AFAIK there is no way to get data from a spreadsheet old revision, ie, number of sheets, sheets names, etc., but nowadays it's possible to get some metadata of some spreadsheet revisions by using the Advanced Drive Service

function logRevisionMetadata() {
  const fileId = 'put here your spreadsheet ID';
  const output = [];
  // Get revisions
  var revisions = Drive.Revisions.list(fileId, { 'maxResults': 1000 });
  console.log("Found " + revisions.items.length + " revisions");
  
 revisions.items.forEach( revision => {
      var date = new Date(revision.modifiedDate);
      output.push([Utilities.formatDate(date,'GMT-5','yyyy-MM-dd HH:mm'), revision.lastModifyingUser.displayName]);
    });
  console.log(output)
}

When I ran the above code for one of my spreadsheets I got only 24 revisions (only revisions from the current month and some of the previous month, the revisions from the previous 5 months were missing). This was already reported in the issue tracker Google Drive revision.list() does not return all stored revisions for a Google Sheets Spreadsheet

Related

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM