Laravel-excel: [BUG] Row Headings not being added

Created on 2 Mar 2020  路  2Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites

  • [ X ] Checked if your Laravel Excel version is still supported: https://docs.laravel-excel.com/3.1/getting-started/support.html#supported-versions
  • [ X ] Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • [ X ] Checked that your issue isn't already filed.
  • [ X ] Checked if no PR was submitted that fixes this problem.
  • [ X ] Filled in the entire issue template

Versions

  • PHP version: 7.3
  • Laravel version: 6.17.1
  • Package version: 3.1.19

Description

I want to export an excel sheet with "xslx" extension and make custom header Name, Iso for Countries that I have used this plugin for it laravel-countries

Steps to Reproduce

The export class app/Exports/GeoExport.php

<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithMapping;
use Webpatser\Countries\Countries;

class GeoExport implements FromQuery, WithHeadingRow, WithMapping
{
    use Exportable;

    /**
     * @return array
     */
    public function headings(): array
    {
        return [
            'Name',
            'ISO'
        ];
    }

    public function map($countries) : array
    {
        return [
            $countries->name,
            $countries->iso_3166_2
        ];
    }

    public function query()
    {
        return Countries::query()->select(['name','iso_3166_2']);
    }
}

The export method in my controller exportGeoCountryList

    public function exportGeoCountryList()
    {
        return (new GeoExport)->download('geo_countries.xlsx');
    }

Expected behavior:


Screenshot from 2020-03-02 18-25-13

Actual behavior:

Screenshot from 2020-03-02 18-24-34

Additional Information

All steps depend on the documentation in this link

bug

Most helpful comment

As noted in the documentation link you shared, the concern is WithHeadings. WithHeadingRow is the concern used for Imports.

All 2 comments

As noted in the documentation link you shared, the concern is WithHeadings. WithHeadingRow is the concern used for Imports.

Thanks a lot I didn't see that there is difference between WithHeadings and WithHeadingRow 馃檲

Was this page helpful?
0 / 5 - 0 ratings

Related issues

contifico picture contifico  路  3Comments

dr3ads picture dr3ads  路  3Comments

vandolphreyes picture vandolphreyes  路  3Comments

lucatamtam picture lucatamtam  路  3Comments

gamevnlc picture gamevnlc  路  3Comments