2

我在 Laravel 中使用 Maatwebsite,它是 excel 作品的一个很好的选择,但我有一个问题.. 我有带有阿拉伯标题的 excel 表,所以当我导入它时,它转换为难以理解的英文字符以适合数组键..那么我的问题的解决方案是什么?

4

4 回答 4

3

我知道为时已晚,但对于可能有同样问题的其他人,您应该在 config/excel.php 文件的“import”数组中将“heading”键的值更改为“original”。

'import' => [
    ...
    'heading' => 'original',
],
于 2017-05-21T17:02:07.573 回答
2

http://www.maatwebsite.nl/laravel-excel/docs/import

查找有关导入编码的标题。

从那些页面:

// When utilising a closure, you can pass the input encoding as third parameter.
Excel::load('filename.csv', function($reader) {

}, 'UTF-8');

// or without a closure, you can use it as second parameter.
Excel::load('filename.csv', 'UTF-8');

这能解决问题吗?

于 2015-12-21T14:41:26.650 回答
0

我为时已晚,但这对我来说是工作,而不是修改 import.php,在你的控制器中添加这个

config(['excel.import.heading' => 'original' ]);
于 2018-06-27T14:23:22.793 回答
0

您可以在类导入中实现 WithCustomCsvSettings 的接口

例子:

<?php
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;


class ArticlesImport implements ToCollection, WithCustomCsvSettings
{
  public function collection(Collection $rows)
  { 
    // do something
  }

  public function getCsvSettings(): array
  {
    # Define your custom import settings for only this class
    return [
        'input_encoding' => 'UTF-8',
        'delimiter' => ";"
    ];
  }

  

}

于 2021-07-02T19:24:54.643 回答