Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change all cell's height and width in laravel excel

Tags:

php

laravel

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.

like image 339
Dipak Dendage Avatar asked Sep 29 '22 10:09

Dipak Dendage


1 Answers

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');
like image 62
Dipak Dendage Avatar answered Oct 20 '22 21:10

Dipak Dendage