0

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,

enter image description here

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

enter image description here

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,

enter image description here

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.

Nabil Farhan
  • 1,444
  • 3
  • 25
  • 41
  • 1
    Might be related to [this other answer](https://stackoverflow.com/questions/34397671/import-utf-8-headings-maatwebsite-laravel) regarding the heading encoding. – noevidenz Sep 10 '19 at 06:30
  • Yes. It was related to that answer. I solved the problem. :D – Nabil Farhan Sep 10 '19 at 06:41
  • Not entirely related, but "level" in katakana is 「レベル」. What you have here is 「ラベル」, which means "label". – Skeets Sep 10 '19 at 06:49

2 Answers2

2

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.

Nabil Farhan
  • 1,444
  • 3
  • 25
  • 41
0

Or you can also put these above, outside your function

use Maatwebsite\Excel\Imports\HeadingRowFormatter;
HeadingRowFormatter::default('none');
Adam Ross
  • 1
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 15 '22 at 23:23