Maatwebsite/Laravel-Excel Import 将特殊字符转换为数字 0
Maatwebsite/Laravel-Excel Import converts special Characters into number 0
我有一个 CSV 文件,其中一些行 text/words 包含特殊字符,例如 ñ、
发生的事情是,当我尝试导入 CSV 文件时,上面或类似字符的单词将被转换为 0.
我正在使用 ToModel
use Maatwebsite\Excel\Concerns\ToModel;
要重现这一点,只需尝试在 CSV 文件的一个单元格中放入一个特殊字符,然后像这样导入它:
Excel::import(new CsvImport, request()->file('file'));
Output : The resulting inserted data that has a special character will be stored as 0
注意:直接从Form添加数据不会将特殊字符转换为0,仅当通过import
上传CSV时
在您的配置中将 'use_bom' 设置为 'true'
'csv' => [
'delimiter' => ',',
'enclosure' => '"',
'line_ending' => PHP_EOL,
'use_bom' => true,
'include_separator_line' => false,
'excel_compatibility' => false,
],
这对我有用:
$data = Excel::load('file.csv', false, 'ISO-8859-1');
或者在excelconfig/excel.php
的文件配置中
'csv' => [
'delimiter' => ';',
'input_encoding' => 'ISO-8859-1',
'enclosure' => '"',
'line_ending' => PHP_EOL,
'use_bom' => false,
'include_separator_line' => false,
'excel_compatibility' => true,
],
我有一个 CSV 文件,其中一些行 text/words 包含特殊字符,例如 ñ、
发生的事情是,当我尝试导入 CSV 文件时,上面或类似字符的单词将被转换为 0.
我正在使用 ToModel
use Maatwebsite\Excel\Concerns\ToModel;
要重现这一点,只需尝试在 CSV 文件的一个单元格中放入一个特殊字符,然后像这样导入它:
Excel::import(new CsvImport, request()->file('file'));
Output : The resulting inserted data that has a special character will be stored as 0
注意:直接从Form添加数据不会将特殊字符转换为0,仅当通过import
上传CSV时在您的配置中将 'use_bom' 设置为 'true'
'csv' => [
'delimiter' => ',',
'enclosure' => '"',
'line_ending' => PHP_EOL,
'use_bom' => true,
'include_separator_line' => false,
'excel_compatibility' => false,
],
这对我有用:
$data = Excel::load('file.csv', false, 'ISO-8859-1');
或者在excelconfig/excel.php
的文件配置中 'csv' => [
'delimiter' => ';',
'input_encoding' => 'ISO-8859-1',
'enclosure' => '"',
'line_ending' => PHP_EOL,
'use_bom' => false,
'include_separator_line' => false,
'excel_compatibility' => true,
],