Reputation: 35
How to manipulate the codes so that the styling of a cell so that it can achieve something like the image below where only the bottom of the cell is underlined?
Currently, my code only allow the styling of the cell with full border on all four sides using Laravel excel 3.1. How do I only apply border style on only one side of the cell? Thanks
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->mergeCells('C13:E13');
$event->sheet->getDelegate()->getCell('C13')->setValue('DESCRIPTION');
$event->sheet->getDelegate()->getStyle('C13')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$event->sheet->getDelegate()->mergeCells('A1:G1');
$event->sheet->getDelegate()->getCell('A1')->setValue('INVOICE');
$event->sheet->getDelegate()->getStyle('A1')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
$event->sheet->styleCells(
'A13:G13',
[
'borders' => [
'outline' => [
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN
],
]
]
);
$event->sheet->styleCells(
'G3',
[
'font' => [
'name' => 'Calibri',
'size' => 15,
'bold' => true,
'color' => ['argb' => 'EB2B02'],
],
]
);
$event->sheet->styleCells(
'F47:G47',[
'borders' =>[
'outline' =>[
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_DOUBLE
]
]
]
);
},
];
}
Upvotes: 1
Views: 7924
Reputation: 21
you can change the position (right,left,top,buttom) as per your need Exmple showin right side border for the cell "P2" :
$rightBorder=array(
'borders' => [
'right' => [
'borderStyle' => Border::BORDER_THIN,
'color' => ['argb' => '000000'],
],
],
);
$event->sheet->getStyle("P2")->applyFromArray($rightBorder);
Upvotes: 1
Reputation: 765
try this
'borders' => [
'bottom' => [
'borderStyle' => Border::BORDER_DOUBLE,
]
],
I manage to do it with
$sheet->getStyle('A3:Y3')->applyFromArray([
'borders' => [
'bottom' => [
'borderStyle' => Border::BORDER_THICK,
]
],
]);
Upvotes: 0