简体   繁体   中英

Only Bottom border for laravel excel

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  
                        ]
                    ]
                ]
                );
         },
    ];
}

这是预期的结果

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,
        ]
    ],
]);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM