How to insert a column in Google spreadsheet?

Viewed 3040

I want to add new data to the start (beginning) of the sheet. So I have to add a new column A1 to the sheet. But I can't find any API example with PHP.

Now I am appending the data with this:

$body   = new Google_Service_Sheets_ValueRange(['values' => $values]);
$result = $service->spreadsheets_values->append($new_sheet_id, 'A1:E1', $body, $options); // appent the data to the spreadsheet

Thanks.

UPD: here is what I have found

/* insert columns */
$requests = new Google_Service_Sheets_Request(array(
    'insertDimension' => array(
        'range' => array(
            'sheetId' => 0,
            'dimension' => "COLUMNS",
            'startIndex' => 0,
            'endIndex' => 5
        )
    )
));
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
    'requests' => $requests
));
$result = $service->spreadsheets->batchUpdate($new_sheet_id, $batchUpdateRequest);
/* insert columns */
1 Answers
Related