我使用Google Sheet API第4版。 我想让所有工作表命名为该电子表格文件中的可用内容? 所以如果你有任何办法,请告诉我。感谢
答案 0 :(得分:0)
我们可以调用电子表格对象来获取电子表格的所有信息。
$service = new Google_Service_Sheets($client);
$spreadsheetId = 'your spredsheetid';
$sheetInfo = $service->spreadsheets->get($spreadsheetId);
$allsheet_info = $sheetInfo['sheets'];
$idCats = array_column($allsheet_info, 'properties');
由于
答案 1 :(得分:0)
public function GoogleServiceSheets(){
$client = new \Google_Client();
$client->setApplicationName('Sheets');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig(GOOGLE_CREDENTIALS);
$service = new Google_Service_Sheets($client);
return $service;
}
public function getSheetID_SheetName($spreadsheetID){
$service = $this->GoogleServiceSheets();
$sheetNumberCounter = 1;
$spreadSheetArr = [];
$worksheetSheets = $service->spreadsheets->get($spreadsheetID)->sheets;
foreach($worksheetSheets as $sheet){
$id = $sheet->properties['sheetId'];
$name = $sheet->properties['title'];
$singleSheetArr = array(
'id'=>$id,
'name'=>$name
);
$spreadSheetArr[$sheetNumberCounter] = $singleSheetArr;
$sheetNumberCounter = $sheetNumberCounter + 1;
}
return $spreadSheetArr;
}
答案 2 :(得分:-1)
Google api允许这样做。
你需要做api电话:
https://spreadsheets.google.com/feeds/worksheets/key/public/basic?alt=json
“密钥”是您的电子表格。
祝你好运!