I want to apply height and width for all row's in laravel excel
I am able to change height and width for single row at time by using following code
$sheet->setSize('A1', 25, 18);
$sheet->setSize('B1', 25, 18);
$sheet->setSize('C1', 25, 18);
$sheet->setSize('D1', 25, 18);
$sheet->setSize('E1', 25, 18);
$sheet->setSize('F1', 25, 18);
Now question is I have thousands of rows so How I can manage that ?
I have following code
\Excel::create('Users Report'.$time, function ($excel) use ($arrUsers) {
$excel->sheet('Users', function ($sheet) use ($arrUsers) {
// Set all margins
$sheet->fromArray($arrUsers, null, 'A1', true);
$sheet->setSize('A1', 25, 18);
$sheet->setSize('B1', 25, 18);
$sheet->setSize('C1', 25, 18);
$sheet->setSize('D1', 25, 18);
$sheet->setSize('E1', 25, 18);
$sheet->setSize('F1', 25, 18);
$sheet->row(1, array(
'Name', 'Username', 'Contact', 'Email', 'Verified', 'Inactivity'
));
// Freeze first row
$sheet->freezeFirstRow();
$sheet->cell('A1:F1', function($cell) {
// Set font
$cell->setFont(array(
'family' => 'Calibri',
'size' => '12',
'bold' => true
));
});
});
})->store('xls')->download('xls');
Please help me out from this stuck.
Thanks.
Solve this by using the following code
\Excel::create('Users Report'.$time, function ($excel) use ($arrUsers) {
$excel->sheet('Users', function ($sheet) use ($arrUsers) {
// Set all margins
$sheet->fromArray($arrUsers, null, 'A1', true);
for( $intRowNumber = 1; $intRowNumber <= count($arrUsers) + 1; $intRowNumber++){
$sheet->setSize('A' . $intRowNumber, 25, 18);
$sheet->setSize('B' . $intRowNumber, 25, 18);
$sheet->setSize('C' . $intRowNumber, 25, 18);
$sheet->setSize('D' . $intRowNumber, 25, 18);
$sheet->setSize('E' . $intRowNumber, 25, 18);
$sheet->setSize('F' . $intRowNumber, 25, 18);
}
$sheet->row(1, array(
'Name', 'Username', 'Contact', 'Email', 'Verified', 'Inactivity'
));
// Freeze first row
$sheet->freezeFirstRow();
$sheet->cell('A1:F1', function($cell) {
// Set font
$cell->setFont(array(
'family' => 'Calibri',
'size' => '12',
'bold' => true
));
});
});
})->store('xls')->download('xls');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With