set background color to rows in Php excel #3033
Unanswered
NikhilGarakapati
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
Sample Excel data https://i.stack.imgur.com/4uV2j.png
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 https://i.stack.imgur.com/UGghi.png
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?
Beta Was this translation helpful? Give feedback.
All reactions