How do I rename a (work)sheet in a Google Sheets spreadsheet using the API in Python?

This is an extraction of a library which I’ve coded personally: def _batch(self, requests): body = { ‘requests’: requests } return self._service.spreadsheets().batchUpdate(spreadsheetId=self.spreadsheetId, body=body).execute() def renameSheet(self, sheetId, newName): return self._batch({ “updateSheetProperties”: { “properties”: { “sheetId”: sheetId, “title”: newName, }, “fields”: “title”, } }) I think that with a little effort, you can implement it into your … Read more

Chrome Extension Writing to Google Spreadsheet [closed]

Yes, it is definitely possible. I have used the Spreadsheet API extensively using Javascript. You’ll need to use the Protocol version of the API as documented here: https://developers.google.com/google-apps/spreadsheets/ This requires sending signed requests using OAuth2 (the older auth protocols aren’t really reliable anymore.) so I suggest using an OAuth2 library like JSO. https://github.com/andreassolberg/jso When writing … Read more

How to convert Time into decimal float in Google Sheets using Script?

Google Sheets In Google Sheets, if you have a date/time value in a cell (e.g. “D9”), then use =HOUR(D9)+(MINUTE(D9)/60). If the value is stored in the format 04:29, then use =INDEX(SPLIT(D9, “:”), 1) + (INDEX(SPLIT(D9, “:”), 2)/60). Google Sheets API & Google Apps Script If you want to use the Google Sheets API or Google … Read more

How do you insert a single row into Google sheets using Sheets APIv4 Java

I was able to figure this one out after lots of googling, some struggling and adapting another answer. Note: You can generate your own credentials.json. This goes in your “resources” folder in most IDEs. Here’s the code that I used, in full – the relevant method that you will need is the insertRow method below, … Read more

External API call in Google Spreedsheet is possible?

There’s a way to make API calls and have the results go into a spreadsheet – the only way I know to do it is create/open the target spreadsheet, go to tools and then Script editor, and use this as a bound script: function Maestro() { var ss = SpreadsheetApp.getActiveSpreadsheet(); //get active spreadsheet (bound to … Read more

How to automatically import data from uploaded CSV or XLS file into Google Sheets

You can programmatically import data from a csv file in your Drive into an existing Google Sheet using Google Apps Script, replacing/appending data as needed. Below is some sample code. It assumes that: a) you have a designated folder in your Drive where the CSV file is saved/uploaded to; b) the CSV file is named … Read more

Download a spreadsheet from Google Drive / Workspace using Python

The https://github.com/burnash/gspread library is a newer, simpler way to interact with Google Spreadsheets, rather than the old answers to this that suggest the gdata library which is not only too low-level, but is also overly-complicated. You will also need to create and download (in JSON format) a Service Account key: https://console.developers.google.com/apis/credentials/serviceaccountkey Here’s an example of … Read more

Get list of sheets and latest sheet in google spreadsheet api v4 in Python

You can get a list of sheets by using the “get” method on spreadsheets: sheet_metadata = service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute() sheets = sheet_metadata.get(‘sheets’, ”) title = sheets[0].get(“properties”, {}).get(“title”, “Sheet1”) sheet_id = sheets[0].get(“properties”, {}).get(“sheetId”, 0)

Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential

Not possible. You need to use the OAuth login as indicated here in spreadsheets.values.batchUpdate: You can see on the authorization part that it uses OAuth scopes, therefore it follows that it uses OAuth not API KEY: Authorization Requires one of the following OAuth scopes: https://www.googleapis.com/auth/drive https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/spreadsheets