我正在使用laravel excel上传excel文件。该文件的标题位于最顶部。但是,如果标题为日语,则无法正确处理。
例如,如果我的文件是
+---------+--------+-------+
| bango | name | level |
+---------+--------+-------+
| nihongo | 日本語 | 8 |
+---------+--------+-------+
| test01 | test01 | 12 |
+---------+--------+-------+
它给出以下输出,
这是正确的输出。 但是,当我将标题更改为包括日语时,它将无法正常工作。 我的文件就像
+---------+--------+--------+
| 番号 | 名前 | ラベル |
+---------+--------+--------+
| nihongo | 日本語 | 8 |
+---------+--------+--------+
| test01 | test01 | 12 |
+---------+--------+--------+
输出变为
我测试过将其混合使用,并在其中添加了一些英语标题和一些日语标题。 我的文件就像
+---------+--------+--------+
| 番号 | name | ラベル |
+---------+--------+--------+
| nihongo | 日本語 | 8 |
+---------+--------+--------+
| test01 | test01 | 12 |
+---------+--------+--------+
我的结果变成
尽管,结果正确给出了name
的值,但是序列不正确。 name
的值应在level
之前,但不是。
我的控制器功能就像
public function post($id)
{
$array = (new DeliveryImport)->toArray(request('file'));
dd($array);
}
我的DeliveryImport.php就像
class DeliveryImport implements ToModel, WithHeadingRow
{
use Importable;
public function model(array $row)
{
}
}
请注意,该代码仅在标题中包含日语时才起作用。如果其他地方有日语,那么它可以正常工作。
答案 0 :(得分:0)
我已经解决了问题。解决方案是更改config/excel.php
。
在该文件中找到imports' => 'heading_row'
。
然后将formatter
从slug
更改为none
。
此后,它完美地工作了。