Reputation: 1536
I am using laravel excel to upload a excel file. The file contains heading at the very top. However, when the heading is in Japanese it is not being processed properly.
For example, if my file is like
+---------+--------+-------+
| bango | name | level |
+---------+--------+-------+
| nihongo | 日本語 | 8 |
+---------+--------+-------+
| test01 | test01 | 12 |
+---------+--------+-------+
It gives the following output,
This is the correct output. However, when I change the heading to include Japanese then it doesn't work correctly. My file is like,
+---------+--------+--------+
| 番号 | 名前 | ラベル |
+---------+--------+--------+
| nihongo | 日本語 | 8 |
+---------+--------+--------+
| test01 | test01 | 12 |
+---------+--------+--------+
The output becomes
I tested to mix this and put some headers in English and some in Japanese. My file is like,
+---------+--------+--------+
| 番号 | name | ラベル |
+---------+--------+--------+
| nihongo | 日本語 | 8 |
+---------+--------+--------+
| test01 | test01 | 12 |
+---------+--------+--------+
And my result becomes,
Although, the result gives name
values correctly but the serial is incorrect. name
values should be before level
but it is not.
My controller function is like,
public function post($id)
{
$array = (new DeliveryImport)->toArray(request('file'));
dd($array);
}
And my DeliveryImport.php is like,
class DeliveryImport implements ToModel, WithHeadingRow
{
use Importable;
public function model(array $row)
{
}
}
Please, note that, the code doesn't work only when there are Japanese on heading. If there is Japanese on other places then it works without a problem.
Upvotes: 0
Views: 1328
Reputation: 11
Or you can also put these above, outside your function
use Maatwebsite\Excel\Imports\HeadingRowFormatter;
HeadingRowFormatter::default('none');
Upvotes: 1
Reputation: 1536
I have solved the problem. The solution is to change in config/excel.php
.
In that file find imports' => 'heading_row'
.
Then change the formatter
from slug
to none
.
It worked flawlessly after that.
Upvotes: 2