Mohamed Gamal
Mohamed Gamal

Reputation: 401

Import utf-8 headings Maatwebsite Laravel

I'm using Maatwebsite in Laravel and it's very good option for excel works but I have one problem .. I have excel sheet with arabic heading, so when I import it , it converted to understand-less english character to fit array key .. So What is the solution for my problem?

Upvotes: 2

Views: 8437

Answers (4)

Gustavo Marquez
Gustavo Marquez

Reputation: 499

You can implements the Interface of WithCustomCsvSettings, in your class import

Example:

<?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' => ";"
    ];
  }

  

}

Upvotes: 1

Rix
Rix

Reputation: 1

I'm too late but this workerd for me, instead of a modifying import.php, in your controller add this

config(['excel.import.heading' => 'original' ]);

Upvotes: 0

Dena
Dena

Reputation: 41

I know it's too late, but for someone else that may have the same problem, you should change the value of "heading" key to "original" in "import" array of config/excel.php file..

'import' => [
    ...
    'heading' => 'original',
],

Upvotes: 3

Erwin Moller
Erwin Moller

Reputation: 2408

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

Look up the header about import encoding.

From thoose pages:

// 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');

Does that solve the issue?

Upvotes: 2

Related Questions