I'm using laravel framework to export an excel. I'm using a manual procedure to set background colors to particular rows. Here's the sample excel data
In the above example, I want to set a color to the entire rows that contains a text in second column. Likewise adding a BG color to the entire rows that contains a text in second column.
Excel after setting the BG colors
I've tried this manual adding
use Illuminate\Support\Facades\App;
use Maatwebsite\Excel\Facades\Excel;
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');
});
};
How can I do it dynamically by using conditions to set the background colors?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire