LaravelExcel is converting the header values of an excel spreadsheet. How to disable this?

1

I'm using the LaravelExcel library to import data from an excel into a database.

To get the header data from my worksheet, do the following:

Excel::load('file.xls', function($reader) {

     $nomeDasColunas = $reader->get()->first()->keys();

});

But I have the following problem: When my header comes with accented names, hyphens and other characters, they are being converted.

For example. The values:

Nome | E-mail | Número do Cartão

Being converted to

 nome | email | numero_do_cartao

The problem is that I need the original names. I do not want to create a function to "reconvert" the values to the original names, as this would be a shot in the foot.

I tried this solution in everything that is place and I did not find it. I even looked at the source code of the library itself, but I have not found any method that I can define how the headers are read.

Is there any configuration of this library where I can change this name conversion?

    
asked by anonymous 25.07.2016 / 15:53

1 answer

0

I found out. There is really no method in the Excel class that makes the operation to disable automatic column name conversion, but you can configure the library.

There are two ways to do this.

The first is when it comes to a specific case. I do not want to disable automatic conversion to import all excels, but only for a specific operation. We can use the config function and set a value to excel.import.heading .

like this:

config(['excel.import.heading' => 'original']);

I used the original option to keep the original headers in line with the excel sent.

The second was to change the LaravelExcel configuration file to get these import settings globally.

To do this, simply run the command php artisan vendor:publish and, after the config/excel.php file is created, edit the value of array containing index heading (which is within import ). The available options are:

true|false|slugged|slugged_with_count|ascii|numeric|hashed|trans|original

    
25.07.2016 / 17:45