Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
How to remove double quotations from exported csv file

I'm using Laravel 5.8 and I have added Maatwebsite package for exporting CSV files from a database table.

And here is my exported class:

class ConfirmedExport implements FromCollection, WithHeadings
{
    public function headings():array{
        return [
   
        ];
    }

    public function collection()
    {
        return collect(WithdrawWallet::getData());
    }
}

And the result looks like this:

"123456789","2100","Desc","lname","fname"

But I need to remove double quotations (" ") from the words, so the expected result looks like this:

123456789,2100,Desc,lname,fname

So how to do that?


UPDATE #1:

I just tried this code for Export Class:

namespace App\Exports;

use App\WithdrawWallet;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class ConfirmedExport implements FromCollection, WithHeadings
{
    public function headings():array{
        return [
   
        ];
    }

    public function collection()
    {
        return collect(WithdrawWallet::getData());
    }
    
    public function getCsvSettings(): array
    {
        return [
            'enclosure' => ''
        ];
    }
}

And it successfully removes the " " from the last element (which is: 123456789), but still shows the " " for the other ones!

enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

@nagidi after you publish the config you may change this in the settings.

  1. Run following command:

    php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
    
  2. Remove " (double quote) from 'enclosure' in config/excel.php

     'exports' => [
         'csv' => [
             'enclosure' => '', // was '"'
             // other settings
         ],
     ],
    

Now your csv export values doesn't contain the " enclosure anymore.

If you want to change this setting per Export, you can implement the WithCustomCsvSettings Concern and add the getCsvSettings method to your ConfirmedExport class:

use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;

class ConfirmedExport implements WithCustomCsvSettings
{
    // other code

    public function getCsvSettings(): array
    {
        return [
            'enclosure' => ''
        ];
    }
}
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda