Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] - How to change the default sheet name ? #1585

Closed
praditha opened this issue Mar 26, 2018 · 3 comments
Closed

[Question] - How to change the default sheet name ? #1585

praditha opened this issue Mar 26, 2018 · 3 comments

Comments

@praditha
Copy link

praditha commented Mar 26, 2018

Versions

  • PHP version: 7.1.9
  • Laravel version: 5.5
  • Package version: 3.0

Description

I cannot find how to change the sheet name in the document for exporting the data into excel file.
Instead of use Worksheet as a default sheet name, I want to change it based on what data I will provide.

Thanks for this excellent package.

My Code

/** Voucher Export Class **/
namespace Modules\VoucherManagement\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use App\Models\Voucher;

class VouchersExport implements FromView
{    
    /**
     * @return View
     */
    public function view(): View
    {
        $vouchers = Voucher::getAllVouchers();
        
        return view('templates.export', [
            'vouchers' => $vouchers
        ]);
    }
}
/*** End of Voucher Export Class ***/

/*** Voucher Controller ***/
public function export(Request $request, Excel $excel, VouchersExport $export)
{        
     return $excel->download($export, 'vouchers.xlsx');
}
/*** End of Voucher Controller ***/
@praditha
Copy link
Author

I've got my answer by implement WithTitle Class and just return the name what we want

use Maatwebsite\Excel\Concerns\WithTitle;
...

class VouchersExport implements FromView, WithTitle {
    ...
    public function title(): string
    {
        return 'Vouchers';
    }
}

@comrade001
Copy link

@praditha era justo lo que necesitaba.

Muchas gracias.

@jgalindosl
Copy link

You should take into account that this works perfectly, as long as your html file doesn't have a <title> attribute on the header. This overrides the WithTitle concern. You should remove the <title> html attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants