Laravel-excel: How can I break the line ?

Created on 7 Aug 2018  路  9Comments  路  Source: Maatwebsite/Laravel-Excel

Hello , I am exporting a file , how can I break the line ? I tried to use
, \n\r ....
I want to do like this -

Hello
World

more information needed

All 9 comments

Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.0/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/docs/3.0/getting-started/contributing) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.

I am using the version 2.1 .
Thanks

Please fill in the issue template and provide more info. Show your code

version 2.1
i am inserting new line like so

$advert = wordwrap($model->advert, config('excel.excel_export.new_line_after_chars'), "\n")

but that is braking the auto calculate height settings
so to fix it i am using the calculation

 $countNewLines = substr_count($advert, "\n");
 $rowsHeight[$rowCounter] = ($countNewLines + 1) * config('excel.excel_export.row_height');

 ...

Excel::create('file_name', function($excel) use ($data, $rowsHeight) {
            $excel->sheet('sheet_name', function($sheet) use ($data, $rowsHeight) {
                $sheet->fromArray($data)
                    ->setHeight($rowsHeight);
            });
 })->store(....);

config

config('excel.excel_export.new_line_after_chars') = 200
config('excel.excel_export.row_height') = 17

i am using utf-8 encoding

Use '\n' and try set wrap text to TRUE for default style.

Excel::create($file_name, function($excel) {           
    $excel->getDefaultStyle()
        ->getAlignment()
        ->applyFromArray(array(
            'horizontal'    => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
            'vertical'      => \PHPExcel_Style_Alignment::VERTICAL_TOP,
            'wrap'      => TRUE
        ));
})->download('xlsx');

@nguyenanhthai The API seems to have changed. But I can't find the proper way to do this in v3.1. Could someone please give a hint?

@nguyenanhthai The API seems to have changed. But I can't find the proper way to do this in v3.1. Could someone please give a hint?

Did you try the suggestion in this thread?

@GlennM Thank you!

I found articles by Laravel News and Laravel Daily which explained that I had to hook into the sheet events to set the wrapping to true.

btw instead of wrapping & \n u can use PHP_EOL

Was this page helpful?
0 / 5 - 0 ratings