Skip to content

Instantly share code, notes, and snippets.

@batFormat
Created September 12, 2021 20:54
Show Gist options
  • Save batFormat/fbc40644f23417035e3813ef4f9d29ac to your computer and use it in GitHub Desktop.
Save batFormat/fbc40644f23417035e3813ef4f9d29ac to your computer and use it in GitHub Desktop.
Merge cells in google sheets
<?php
class Test {
public function test() {
$service = new Google_Service_Sheets(GoogleService::getClient());
$spreadsheetId = 'abcdf';
$values = [
["Item", "Cost", "Stocked"],
["Wheel", "$20.50", "4"]
];
$valueRange = new Google_Service_Sheets_ValueRange([
'values' => $values,
]);
$conf = [
"valueInputOption" => "RAW",
];
$range = "Задачи!A1:C";
$rangeinst = new \Google_Service_Sheets_GridRange();
$rangeinst->setSheetId(0);
$rangeinst->setStartRowIndex(0);
$rangeinst->setEndRowIndex(11);
$rangeinst->setStartColumnIndex(0);
$rangeinst->setEndColumnIndex(2);
$merge = New Google_Service_Sheets_MergeCellsRequest();
$merge->setMergeType('MERGE_COLUMNS');
$merge->setRange($rangeinst);
$requestbody = new \Google_Service_Sheets_Request();
$requestbody->setMergeCells($merge);
$requestBatchBody = new \Google_Service_Sheets_BatchUpdateSpreadsheetRequest();
$requestBatchBody->setRequests($requestbody);
$result = $service->spreadsheets->batchUpdate($spreadsheetId, $requestBatchBody);
dd($result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment