Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用maatexcel库为导出到excel文件的每一列创建边框?_Php_Excel_Csv_Laravel Excel - Fatal编程技术网

Php 如何使用maatexcel库为导出到excel文件的每一列创建边框?

Php 如何使用maatexcel库为导出到excel文件的每一列创建边框?,php,excel,csv,laravel-excel,Php,Excel,Csv,Laravel Excel,我希望为所有数据的每一列和每一行设置边框样式,但不指定特定的单元格范围 这是我在网站文档() 首先,做一个宏观的分析 use \Maatwebsite\Excel\Sheet; Sheet::macro('styleCells', function (Sheet $sheet, string $cellRange, array $style) { $sheet->getDelegate()->getStyle($cellRange)->applyFromArray($

我希望为所有数据的每一列和每一行设置边框样式,但不指定特定的单元格范围

这是我在网站文档()

首先,做一个宏观的分析

use \Maatwebsite\Excel\Sheet;

Sheet::macro('styleCells', function (Sheet $sheet, string $cellRange, array $style) {
    $sheet->getDelegate()->getStyle($cellRange)->applyFromArray($style);
});
然后调用宏函数,如下所示:

namespace App\Exports;

use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Events\BeforeExport;
use Maatwebsite\Excel\Events\AfterSheet;

class InvoicesExport implements WithEvents
{
    /**
     * @return array
     */
    public function registerEvents(): array
    {
        return [
            BeforeExport::class  => function(BeforeExport $event) {
                $event->writer->setCreator('Patrick');
            },
            AfterSheet::class    => function(AfterSheet $event) {
                $event->sheet->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);

                $event->sheet->styleCells(
                    'B2:G8',
                    [
                        'borders' => [
                            'outline' => [
                                'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
                                'color' => ['argb' => 'FFFF0000'],
                            ],
                        ]
                    ]
                );
            },
        ];
    }
}
这很好,但它只指定特定的单元格范围(上面示例中的B2:G8),我的数据是动态的,无法指定单元格范围