SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.29k stars 1.92k forks source link

Rotate PDF export #537

Closed J1Duran closed 9 years ago

J1Duran commented 9 years ago

Hello I have a question, How do I export horizontal PDF sheet? My table exceeds the size of the page. captura de pantalla de 2015-09-09 14 37 37

patrickbrouwers commented 9 years ago

did you try the orientation setting? $sheet->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE)

J1Duran commented 9 years ago

Class PHPExcel_Worksheet_PageSetup' not found. I need to include a something?

patrickbrouwers commented 9 years ago

If you have a namespaced class, you need to import it:

<?php

namespace YourNamespace;

use PHPExcel_Worksheet_PageSetup;

class YourClass {

}
J1Duran commented 9 years ago

Thank you. Any idea that does not exceed the size of the page? pag

patrickbrouwers commented 9 years ago

Is bigger paper size an option?

J1Duran commented 9 years ago

How I do this?

patrickbrouwers commented 9 years ago
$sheet->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A3)

and use one of the constants in PHPExcel_Worksheet_PageSetup listed here: http://www.osakac.ac.jp/labs/koeda/tmp/phpexcel/Documentation/API/PHPExcel_Worksheet/PHPExcel_Worksheet_PageSetup.html

J1Duran commented 9 years ago

Thanks man.

aurawindsurfing commented 6 years ago

Hi @patrickbrouwers,

How the same could be implemented in Laravel Excel Nova please? Where to put it please? Here is my code just not sure what public function to overwrite to get it across.

<?php

namespace App\Nova\Actions;

use Illuminate\Bus\Queueable;
use Laravel\Nova\Actions\Action;
use Illuminate\Support\Collection;
use Laravel\Nova\Fields\ActionFields;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;

class ExportToPdf extends DownloadExcel implements ShouldAutoSize
{

     (PageSetup::ORIENTATION_LANDSCAPE);
     (PageSetup::PAPERSIZE_A4);

}
patrickbrouwers commented 6 years ago

@aurawindsurfing

You can add custom concerns to your export: https://laravel-excel.maatwebsite.nl/3.1/exports/extending.html . In there you can call the native page setup methods on the delegate.

class ExportToPdf extends DownloadExcel implements ShouldAutoSize, \Maatwebsite\Excel\Concerns\WithEvents
{

/**
     * @return array
     */
    public function registerEvents(): array
    {
        return [

            AfterSheet::class    => function(AfterSheet $event) {
                 $sheet->getDelegate()->getPageSetup()->setOrientation($PageSetup::ORIENTATION_LANDSCAPE);
            },
        ];
    }

}

Then

aurawindsurfing commented 6 years ago

Thanks!

riteshkhatri commented 4 years ago

Below code work for me,

public function registerEvents(): array
    {
        return [
            AfterSheet::class => function (AfterSheet $event) {
                $event->sheet->getDelegate()->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
            },
        ];
    }

but i want paper size up to content is, can anyone help me out.

vcaraseni commented 4 years ago

@riteshkhatri did you find the way how to make paper size up to content ?