Laravel-excel: [QUESTION] CSV delimiter messed up when exporting many rows without enclosure

Created on 10 Jun 2020  路  4Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

Versions

  • PHP version: 7.3.18
  • Laravel version: 7.13.0
  • Package version: 3.1

    Description

It鈥檚 fine when exporting around 1k rows without enclosure. I'm using queue export and CSV delimiter starting mess up when exporting above 4k rows. Rows and Headings contain space. I'm using Query Builder. I want to export my .csv file without enclosure.

Additional Information

ReportsController

class ReportsController extends Controller 
{
    public function export() 
    {
        (new ReportsExport)->queue('reports.csv');

        return response()->json([
               'download_link' => Storage::url('reports.csv')
        ]);
    }
}

ReportsExport

class ReportsExport implements FromQuery, WithMapping, WithHeadings, WithCustomCsvSettings
{
    use Exportable;

    public function query() 
    {
        // Actually, I'm performing complex query behind the scenes
        // and I do not use "get()" as the doc says...
        $record = DB::table('reports')->orderBy('id', 'asc');

        return $record;
    }

    public function map($record): array
    {
        return [
            $record->column_1,
            ...
        ];
    }

    public function headings(): array
    {
        return [
            "Heading 1"
            ...
        ];
    }

    public function getCsvSettings(): array
    {
        return [
            'enclosure' => ''  // no enclosure
        ];
    }
}
question

Most helpful comment

Apparently there was a breaking change in PhpSpreadsheet, our next release will handle empty enclosures again. Hopefully that will also sole your problem.

All 4 comments

I don't understand what you mean with mess up, can you show the output that you think is wrong

Without Enclosure

around 1k rows

Full Name,First Name,Last Name,Location,Email Address
John Smith Doe,John Smith,Doe,15 Street,[email protected]
Mary Chris Brown,Mary Chris,Brown,15 Aveune,[email protected]

about 4k rows

Full,Name,First,Name,Last,Name,Location,Email,Address
John,Smith,Doe,John,Smith,Doe,15,Street,[email protected],,,,,
Mary,Chris,Brown,Mary,Chris,Brown,15,Aveune,[email protected],,,,,,,

Note: Space disappears and additional commas appear at the end of the rows

Not sure. Think you can better ask on Stackoverflow. We use PhpSpreadsheet behind the scenes and I believe they just use fputcsv. Someone there might be able to explain.

Apparently there was a breaking change in PhpSpreadsheet, our next release will handle empty enclosures again. Hopefully that will also sole your problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

muhghazaliakbar picture muhghazaliakbar  路  3Comments

bahmanyaghoobi picture bahmanyaghoobi  路  3Comments

disto picture disto  路  3Comments

lucatamtam picture lucatamtam  路  3Comments

rossjcooper picture rossjcooper  路  3Comments