laravellaravel-excelmaatwebsite-excel

how to select all the cells in this maatwebsite laravel?


I am trying to format my cells to align center. In the documentation There is example to select a specific cell and cell range only. how do i format the entire sheet to have everything center aligned?

$sheet->cells('A1:A5', function($cells) {

// manipulate the range of cells

});

I want to select all cells instead of a range


Solution

  • You can change the layout of the entire excel sheet using the following code

     Excel::create('Filename', function($excel) {
     $excel->getDefaultStyle()
        ->getAlignment()
        ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER)
    });
    

    This will center all cells horizontally. To center them vertically, add

    Excel::create('Filename', function($excel) {
    $excel->getDefaultStyle()
        ->getAlignment()
        ->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER)
    });