I want to set top border for all cell in range given. But , the border only applied to first cell from the range. I have tried another type of styling, fill cell colour. It works for all cell in range. Same code has been used for single cell and cells in range
<?php
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
//border
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
$spreadsheet = new Spreadsheet();
$activeWorksheet = $spreadsheet->getActiveSheet();
$spreadsheet->getActiveSheet()->getStyle('B2')->getBorders()->getTop()- >setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK);
$spreadsheet->getActiveSheet()->getStyle('D2:D4')->getBorders()->getTop()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK);
$spreadsheet->getActiveSheet()->getStyle('F2')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('FFFF0000'); ;
$spreadsheet->getActiveSheet()->getStyle('H2:H4')->getFill()->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID)->getStartColor()->setARGB('FFFF0000');
$styleArray = [
'borders' => [
'top' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
],
],
];
$spreadsheet->getActiveSheet()->getStyle('J2:J4')->applyFromArray($styleArray);
$writer = new Xlsx($spreadsheet);
$writer->save('output_rangeStyling.xlsx');
?>
I have tried use $spreadsheet->getActiveSheet()->getStyle($rangeTotal)->applyFromArray($styleArray);
, but not work for all cell in range. Is there any option rather than loop to set border for cell range?
thank you.