With PHP, it is unclear from the Google Sheets API v4 documentation on how to create a new sheet (aka "tab") in an existing spreadsheet.
I can do it with batchUpdate, oddly, via the API Explorer, but they don't explain from that how to do this in PHP.
Take a look this
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SERVICE_ACCOUNT_FILE = 'credentials.json'
SPREADSHEET_ID = spreadsheetId
creds = None
creds = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = discovery.build(
'sheets', 'v4', credentials=creds, cache_discovery=False)
batch_update_values_request_body = {
'requests': [
{
'addSheet': {
'properties': {
'title': worksheetName
}
}
}
]
}
request = service.spreadsheets().batchUpdate(
spreadsheetId=SPREADSHEET_ID, body=batch_update_values_request_body)
response = request.execute()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With