シートの先頭に行を挿入する方法
$spreadsheet_id = 'hogehoge';
$requests =
['insertDimension' => [
'range' => [
'sheetId' => 'sheet_idを入れる',
'dimension' => "ROWS",
'startIndex' => 0,
'endIndex' => 1
]
],
];
$batchUpdateRequest = new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest(
array(
'requests' => $requests
)
);
$sheets->spreadsheets->batchUpdate($spreadsheet_id, $batchUpdateRequest);
シートを追加する方法
$spreadsheet_id = 'hogehoge';
$body = new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => [
'addSheet' => [
'properties' => [
'title' => "hoge" . time(),
]
]
]
]);
$response = $sheets->spreadsheets->batchUpdate($spreadsheet_id, $body);
$new_sheet_id = $response->getReplies()[0]->getAddSheet()->getProperties()->sheetId;
var_dump($new_sheet_id);