Create Spreadsheet¶
To create spreadsheets we need to have authentication and authorization, these can be achieved by the usage of the Class Flow
and the object Credentials
for more information we can refer to the documentation in Github.
google-api-python-client/oauth.md at main ยท googleapis/google-api-python-client
in this case, I will copy and modify the code from the example in the quick start form google documentation
We get the use the code to get the credentials and the token need it to interact with the API and return the object service that we will use for the creation of the spreadsheet
create()
method¶
To create a new spreadsheet we will use the method create()
This code is a modification of the example code provided by google
From the above code:
We have the object spreadsheet
with some properties like the title and sheets, these are not the only properties and parameters we can modify for more information we need to check the spreadsheet resources and the sheet resources
REST Resource: spreadsheets | Sheets API | Google Developers
Sheets API | Google Developers
Later we use the method create()
with the object spreadsheet for the parameter body, finally the method execute()
to execute the action.
Finally, use print()
to get the spreadsheet ID, we can use this ID on the browser to find the sheet.
Note the ID in the URL as well as the Sheet ID, at the bottom we have the name of the sheet.
Personal Changes¶
I made some personal changes in the code, adding some type of hint.