Home > Blockchain >  Version History - Google Excel using gspread
Version History - Google Excel using gspread

Time:08-31

I am using gspread library in my python script to connect to the Google excel sheet and I was wondering if there is a way to also grab the version history via gspread library?

CodePudding user response:

From I am using gspread library in my python script to connect to the Google excel sheet, in your situation, I guessed that Google excel sheet is Google Spreadsheet.

About I was wondering if there is a way to also grab the version history via gspread library?, unfortunately, in the current stage, it seems that gspread has no methods for retrieving the revision list of Spreadsheet. But, when googleapis for python is used, the revision list of the Spreadsheet can be retrieved.

In this answer, I would like to propose to retrieve the revision list of Spreadsheet using the client of gspread. Because, in the recent version of gspread, googlapis can be easily used using the client of gspread. And also, gspread includes the scope for using Drive API. I thought that when the client of gspread is used, it might be useful for your situation. The sample script is as follows.

Sample script:

import gspread
from googleapiclient.discovery import build

client = gspread.oauth(
    credentials_filename="###", # Please set your file.
    authorized_user_filename="###", # Please set your file.
)
spreadsheetId = "###" # Please set your Spreadsheet ID.

service = build("drive", "v3", credentials=client.auth)
revisions = service.revisions().list(fileId=spreadsheetId).execute()
print(revisions)
  • When this script is run, the revision list can be retrieved from the Spreadsheet.

Note:

Reference:

  • Related