1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PHPにて、GoogleSpreadSheetApiでの操作方法

Last updated at Posted at 2022-03-01

シートの先頭に行を挿入する方法

$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);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?