Laravel-excel: Multiple sheet export with views is not working

Created on 14 May 2019  路  11Comments  路  Source: Maatwebsite/Laravel-Excel

Multiple sheet export with views is not working

  • PHP version: 7.1
  • Laravel version: 5.6
  • Package version: 3.1

Description

My export:
AttendanceExportMultiple

class AttendanceExportMultiple implements WithMultipleSheets, Responsable
{
    use Exportable;
    protected $logs;

    public function __construct($department, $start_date, $end_date, $logs)
    {
        $this->department = $department;
        $this->start_date = $start_date;
        $this->end_date = $end_date;
        $this->logs = $logs;
    }

    public function sheets(): array
    {
        $sheets = [];
        foreach ($this->logs as $key => $value) {
            $name = $value['first_name'];
            $sheets[] = new AttendanceExportView($this->logs, $name);
        }

        return $sheets;
    }

}

My export class that return view

class AttendanceExportView implements FromView, WithTitle
{
    private $logs;
    private $name;

    public function __construct($logs, $name)
    {
        $this->logs = $logs;
        $this->name = $name;
    }

    public function view(): View
    {
        return view('reports.attendance_export_template', [
            'logs' => $this->logs
        ]);
    }

    /**
     * @return string
     */
    public function title(): string
    {
        return 'Month ' . $this->name;
    }

}

my attendance_export_template.blade.php
since I just testing it first I did not yet put the data

<table>
    <tbody>
    <tr>
        <td>Employee's Name</td>
        <td>test</td>
    </tr>
    <tr>
        <td>Position</td>
        <td>test</td>
    </tr>
    <tr>
        <td>Cut off period of: </td>
        <td>test</td>
    </tr>
    </tbody>
</table>

I am not sure what is the reason it is not working or is this valid?

more information needed

Most helpful comment

CSV doesn't have sheets.

All 11 comments

Thanks for submitting the ticket. Unfortunately the information you provided is incomplete. We need to know which version you use and how to reproduce it. Please include code examples. Before we can pick it up, please check (https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/.github/ISSUE_TEMPLATE.md) and add the missing information. To make processing of this ticket a lot easier, please make sure to check (https://laravel-excel.maatwebsite.nl/3.1/getting-started/contributing.html) and double-check if you have filled in the issue template correctly. This will allow us to pick up your ticket more efficiently. Issues that follow the guidelines correctly will get priority over other issues.

My issue is like this ticket https://github.com/Maatwebsite/Laravel-Excel/issues/1584 but the version of it is 3.0 and mine is 3.1 I am not sure if I missed something.

Hey @Kimmydoray can you clarify what is not working; screenshots, exception stack traces, ... ?

Considering we have a test case setup for multiple sheets with a view, I'd expect it must be something specific to your situation, but without knowing what is not working, it's difficult to judge.

@patrickbrouwers: Here's the issue(see attached image) it is not adding sheets, also the title of the sheet is not changing :(

image

It seems it changed it to something, as test is not the default Excel gives a worksheet without a title.

Would you be able to create a repository that I can clone in which you reproduce your issue. It will be a lot easier (and quicker) for me to check out the issue. A failing unit test in this package is fine too.

@patrickbrouwers: I changed my filename from "test" to "testing" and it also changed the sheet name.
This is how I download the sheet:

return \Excel::download(
     new AttendanceExportMultiple(
        $department, 
        $request->input('start_date'), 
        $request->input('end_date'),
        $logs
    ), 
    $filename
);

Hi sir @patrickbrouwers, my mistake I used the version 3.0.5, is this version already support multiplesheet with views?

It is now working thanks.

Hi sir @patrickbrouwers the multiple sheets with view is not supporting .csv file, it is just working using .xlsx

CSV doesn't have sheets.

@Kimmydoray , multiple sheets with views, did it work??

Was this page helpful?
0 / 5 - 0 ratings