dimanche 14 février 2021

customize excel export in laravel

In my Laravel backend project, I'm trying to customize the excel data while exporting it. I'm adding to add row colors in that excel.

Excel Sheet before customization

public function add_color_to_sheet($sheet) {
    $sheet->cells('A1:E1', function ($cells) {
        $cells->setBackground('#3490ED');
    });
    $sheet->cells('A2:E2', function ($cells) {
        $cells->setBackground('#6D8947');
    });
    $sheet->cells('A3:E3', function ($cells) {
        $cells->setBackground('#0DF3FE');
    });
    $sheet->cells('A8:E8', function ($cells) {
        $cells->setBackground('#0DF3FE');
    });
    $sheet->cells('A11:E11', function ($cells) {
        $cells->setBackground('#6D8947');
    });
    $sheet->cells('A12:E12', function ($cells) {
        $cells->setBackground('#0DF3FE');
    });
    $sheet->cells('A14:E14', function ($cells) {
        $cells->setBackground('#0DF3FE');
    });
  };

Excel Sheet After customization

I'm trying to put a background color for the rows that have only country name in the column, likewise with the state and cities too. Is there any way to customize dynamically using some conditions like if the column contains a country name, that country name rows only should be colored and likewise with the rest?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire