laravel 如何在laravel excel中更改所有单元格的高度和宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29316062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:14:47  来源:igfitidea点击:

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

phplaravel

提问by Dipak Dendage

I want to apply height and width for all row's in laravel excel

我想为 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.

谢谢。

采纳答案by Dipak Dendage

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');