I am using php-google-spreadsheet-client library. I don't know how to get list of sheets available in google sheets. Thanks in advance.
Asked
Active
Viewed 3,893 times
2 Answers
5
<?php
function sheets($spreadsheetID) {
$sheets = array();
// Load Google API library and set up client
// You need to know $spreadsheetID (can be seen in the URL)
$sheetService = new Google_Service_Sheets($client);
$spreadSheet = $sheetService->spreadsheets->get($spreadsheetID);
$sheets = $spreadSheet->getSheets();
foreach($sheets as $sheet) {
$sheets[] = $sheet->properties->sheetId;
}
return $sheets;
}
?>

Nick Weavers
- 534
- 7
- 23
2
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)
You can also check the PHP Quickstart for a PHP command-line application that makes requests to the Google Sheets API.
References: