0

With Laravel Excel, it's easy to add a border to a cell:

$sheet->cell('A1', function($cell) {
    $cell->setBorder('none', 'none', 'thin', 'none')
});

It's easy to add a border to a row too:

$sheet->row(3, function($row) {
    $row->setBorder('none', 'none', 'thin', 'none')
});

But I did not found anything about column (maybe I did not search well). Is it possible to add a border (or some other style) to a whole column?

rap-2-h
  • 30,204
  • 37
  • 167
  • 263

2 Answers2

0

You can do like this i think:

$sheet->setBorder('A1:A10');

This will set border to cells from A1 to A10. so you need to know the length of your column i guess.

Can Vural
  • 2,222
  • 1
  • 28
  • 43
0

1st You have to add event by extends WithEvents and use

 use Maatwebsite\Excel\Concerns\WithEvents;

Then you can apply like this....

public function registerEvents(): array
{
    $alphabetRange  = range('A', 'Z');
    $alphabet       = $alphabetRange[$this->totalValue+6]; // returns Alphabet

    $totalRow       = (count($this->attributeSets) * 3) + count($this->allItems)+1;
    $cellRange      = 'A1:'.$alphabet.$totalRow;

    return [
        AfterSheet::class    => function(AfterSheet $event) use($cellRange) {
            $event->sheet->getStyle($cellRange)->applyFromArray([
                'borders' => [
                    'allBorders' => [
                        'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
                        'color' => ['argb' => '000000'],
                    ],
                ],
            ])->getAlignment()->setWrapText(true);
        },
    ];
}

For Details or more you can follow The doc https://docs.laravel-excel.com/3.1/getting-started/

Zahid Hassan Shaikot
  • 1,066
  • 10
  • 18