Laravel-excel: [misunderstanding] startRow method does not work

Created on 27 Jun 2019  路  4Comments  路  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.6
  • Laravel version: 5.7
  • Package version: 3.1

Description


startRow function does not effect when exporting

Steps to Reproduce

Expected behavior:


when i return the integer value 5 I expect for the sheet to start from the fifth row

Actual behavior:


It always starts from the first row

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Most helpful comment

WithStartRow is an import concern. You are looking for WithCustomStartCell

All 4 comments

Please show us your entire export class

app/Exports/VendorListExport.php (One Sheet)

<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromCollection;
use App\CompanyContact;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithStartRow;

class VendorListExport implements FromCollection, WithMapping, WithHeadings, ShouldAutoSize, WithTitle, WithStartRow
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return CompanyContact::whereHas('company.vendor', function($q) {
           $q->where('form_status', 'approved');
        })->with('company')->with('company.vendor')->get();
    }

    public function map($contact): array
    {
        return [
            $contact->company->vendor->register_code,
            '',
            $contact->company->vendor->user->company_name,
            $contact->company->legal_english_name,
            $contact->company->legal_arabic_name,
            $contact->company->established_at,
            '',
            '',
            '',
            $contact->country,
            $contact->city,
            '',
            '',
            $contact->address,
            '',
            $contact->telephone,
            $contact->fax,
            $contact->email,
            $contact->website,
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            $contact->company->renewal_at,
            '',
            '',
            '',
            '',
            '',
            '',
            '',
            $contact->company->vendor->form_status,
            $contact->company->vendor->user->name,
            $contact->company->vendor->geo_details,
            '',
            '',
            $contact->company->vendor->user->name,
            $contact->company->vendor->company->banks()->first()->name,
            '',
            '',
            $contact->title,
        ];
    }

    public function headings(): array
    {
        return [
            'Vendor Code',
            'Article Association Ref.',
            'Name',
            'Description',
            'Arabic Name',
            'Company Establish Year',
            'Chairman Name',
            'GM Name',
            'Casual Vendor',
            'Country',
            'City',
            'District',
            'Area',
            'Address',
            'PO Box',
            'Telephone',
            'Fax',
            'E-mail',
            'Web Site',
            'Department',
            'Vendor Category',
            'Vendor Type',
            'Tax ID',
            'Register No. at Chamber of Commerce',
            'Register No. at EGPC',
            'Account',
            'Registration Date',
            'Vendor No. at Finance',
            'Vendor No. at Contracts',
            'Comments',
            'Block Date',
            'Block Release Date',
            'Last Renewal Date',
            'Last General Evaluation %',
            'Last General Evaluation Result',
            'Last PO Evaluation %',
            'Last PO Evaluation Date',
            'Last PO Evaluation Result',
            'Last General Evaluation Date',
            'Overall PO Evaluation %',
            'Status',
            'CompanyContact Person',
            'Foreign/Local',
            'Record Flag',
            'Arabic Address',
            'CompanyContact Person_',
            'Bank',
            'Company Geo-Operations',
            'Commercial Reg. Certificate Ref.',
            'CompanyContact Person Job Title',
            'Income TAX Certificate Ref.',
        ];
    }

    public function title() : String
    {
        return 'Approved Vendors List';
    }

    public function startRow() : int
    {
        return 3;
    }
}

app/Exports/ApprovedVendorsExport.php (The Excel)

<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Maatwebsite\Excel\Concerns\Exportable;

class ApprovedVendorsExport implements WithMultipleSheets
{
    use Exportable;

    public function sheets(): array
    {
        $sheets = [];

        $sheets[0] = new VendorListExport;
        $sheets[1] = new ContactListExport;
        $sheets[2] = new CommodityListExport;
        $sheets[3] = new BankListExport;
        $sheets[4] = new AgentListExport;
        $sheets[5] = new DocumentListExport;
        $sheets[6] = new NotesListExport;
        $sheets[7] = new TransactionTracingListExport;

        return $sheets;
    }
}

app/Http/Controllers/Admin/ExportController.php (The Controller)

<?php

namespace App\Http\Controllers\Admin;

use App\Exports\ApprovedVendorsExport;
use App\Http\Controllers\Controller;

class ExportController extends Controller
{
    public function exportApprovedVendors()
    {
        return (new ApprovedVendorsExport)->download('export.xlsx');
    }
}

WithStartRow is an import concern. You are looking for WithCustomStartCell

Sorry for that, I changed the title because it's not really a bug, Thank you

Was this page helpful?
0 / 5 - 0 ratings