Are you looking for snippets that will add spreadsheet cell borders?
Continue down below to check out the different snippets to use in adding spreadsheet cell borders with PhpSpreadsheet or Google Sheets API PHP Client.
PhpSpreadsheet (Excel Files)
/// Set borders to A1
$sheet->getStyle('A1')->getBorders()->getTop()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK);
$sheet->getStyle('A1')->getBorders()->getBottom()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK);
$sheet->getStyle('A1')->getBorders()->getLeft()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK);
$sheet->getStyle('A1')->getBorders()->getRight()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK);
Google Sheets API PHP Client
$requests = [
new Google_Service_Sheets_Request([
'updateBorders' => [
'range' => ['startRowIndex'=> 0, 'endRowIndex'=> 3, 'startColumnIndex'=> 0, 'endColumnIndex'=> 4], // A1:D3
'top'=> ['style'=>'DOTTED', 'colorStyle'=>['rgbColor'=>['red'=>1.0]]],
'left'=> ['style'=>'DOTTED', 'colorStyle'=>['rgbColor'=>['red'=>1.0]]],
'right'=> ['style'=>'DOTTED', 'colorStyle'=>['rgbColor'=>['red'=>1.0]]],
'bottom'=> ['style'=>'DOTTED', 'colorStyle'=>['rgbColor'=>['red'=>1.0]]],
'innerHorizontal'=> ['style'=>'DOTTED', 'colorStyle'=>['rgbColor'=>['red'=>1.0]]],
'innerVertical'=> ['style'=>'DOTTED', 'colorStyle'=>['rgbColor'=>['red'=>1.0]]],
]
])
];
$batchUpdateRequest = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest([
'requests' => $requests
]);
$response = $service->spreadsheets->batchUpdate($spreadsheetId, $batchUpdateRequest);
[you_might_be_interested ids=”236,749″]
Leave a Reply