![](/img/trans.png)
[英]How To Use Google Sheets API v4 To Create New Sheet or Tab in Spreadsheet with PHP
[英]Sheets API v4 - Creating a sheet with custom title, given a spreadsheet
我一直在嘗試這樣做,它創建了工作表,但沒有使用給定工作表的標題。
function addSheet($spreadsheet, $sheet_title) {
$client = getClient();
$service = new Google_Service_Sheets($client);
$response = $service->spreadsheets->batchUpdate($spreadsheet->spreadsheetId, new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
"requests" => [
"addSheet" => new Google_Service_Sheets_AddSheetRequest([
"properties" => new Google_Service_Sheets_SheetProperties([
"title" => $sheet_title
])
])
]
]));
return $response;
}
它出什么問題了?
編輯:我試過了,它似乎正在使用以下內容:
function addSheet($spreadsheet, $sheet_title) {
$client = getClient();
$service = new Google_Service_Sheets($client);
$request_body = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$request_body->setRequests([
"addSheet" => new Google_Service_Sheets_AddSheetRequest([
"properties" => new Google_Service_Sheets_SheetProperties([
"title" => $sheet_title
])
])
]);
$response = $service->spreadsheets->batchUpdate($spreadsheet->spreadsheetId, $request_body);
return $response;
}
但我仍然不明白另一個有什么問題......
$response = $service->spreadsheets->batchUpdate($spreadsheet->spreadsheetId, new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
'requests' => array(
'addSheet' => array(
'properties' => array(
'title' => $sheet_title
)
)
)
)
)
);
無需在Google_Service_Sheets_BatchUpdateSpreadsheetRequest
中創建新對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.