All Projects → Jimmy-JS → Laravel Report Generator

Jimmy-JS / Laravel Report Generator

Licence: mit
Rapidly Generate Simple Pdf, CSV, & Excel Report Package on Laravel

Projects that are alternatives of or similar to Laravel Report Generator

Gotenberg
A Docker-powered stateless API for PDF files.
Stars: ✭ 3,272 (+761.05%)
Mutual labels:  pdf, csv, excel
Laracsv
A Laravel package to easily generate CSV files from Eloquent model
Stars: ✭ 583 (+53.42%)
Mutual labels:  excel, csv, laravel
Report
Report management package in PHP that aims to help you export information in a variety of formats
Stars: ✭ 125 (-67.11%)
Mutual labels:  report, laravel, pdf
Fast Excel
🦉 Fast Excel import/export for Laravel
Stars: ✭ 1,183 (+211.32%)
Mutual labels:  excel, csv, laravel
Tabula
Tabula is a tool for liberating data tables trapped inside PDF files
Stars: ✭ 5,420 (+1326.32%)
Mutual labels:  excel, csv, pdf
Magicodes.ie
Import and export general library, support Dto import and export, template export, fancy export and dynamic export, support Excel, Csv, Word, Pdf and Html.
Stars: ✭ 1,198 (+215.26%)
Mutual labels:  excel, csv, pdf
sheet2dict
Simple XLSX and CSV to dictionary converter
Stars: ✭ 206 (-45.79%)
Mutual labels:  csv, excel
csv2xls
Put together some CSV files into a single Excel file, in different sheets.
Stars: ✭ 14 (-96.32%)
Mutual labels:  csv, excel
exoffice
Library to parse common excel formats (xls, xlsx, csv)
Stars: ✭ 31 (-91.84%)
Mutual labels:  csv, excel
jupyterlab-spreadsheet-editor
JupyterLab spreadsheet editor for tabular data (e.g. csv, tsv)
Stars: ✭ 72 (-81.05%)
Mutual labels:  csv, excel
eec
A fast and lower memory excel write/read tool.一个非POI底层,支持流式处理的高效且超低内存的Excel读写工具
Stars: ✭ 93 (-75.53%)
Mutual labels:  csv, excel
django-excel-response
Django package to easily render Excel spreadsheets
Stars: ✭ 74 (-80.53%)
Mutual labels:  csv, excel
Laravel Nova Excel
🚀 Supercharged Excel exports for Laravel Nova Resources
Stars: ✭ 259 (-31.84%)
Mutual labels:  excel, laravel
StormReport
🌀 Library - Create your reports using only annotations
Stars: ✭ 17 (-95.53%)
Mutual labels:  excel, report
MiniExcel
Fast, Low-Memory, Easy Excel .NET helper to import/export/template spreadsheet
Stars: ✭ 996 (+162.11%)
Mutual labels:  csv, excel
Meza
A Python toolkit for processing tabular data
Stars: ✭ 374 (-1.58%)
Mutual labels:  excel, csv
awesome-georgian-datasets
Useful datasets, specific to Georgia
Stars: ✭ 47 (-87.63%)
Mutual labels:  csv, excel
dbd
dbd is a database prototyping tool that enables data analysts and engineers to quickly load and transform data in SQL databases.
Stars: ✭ 30 (-92.11%)
Mutual labels:  csv, excel
Sq
swiss-army knife for data
Stars: ✭ 275 (-27.63%)
Mutual labels:  excel, csv
Tableexport
tableExport(table导出文件,支持json、csv、txt、xml、word、excel、image、pdf)
Stars: ✭ 261 (-31.32%)
Mutual labels:  csv, pdf

Laravel Report Generators (PDF, CSV & Excel)

Rapidly Generate Simple Pdf Report on Laravel (Using barryvdh/laravel-dompdf or barryvdh/laravel-snappy) or CSV / Excel Report (using Maatwebsite/Laravel-Excel)

This package provides a simple pdf, csv & excel report generators to speed up your workflow

Version

Version Laravel Version Php Version Maatwebsite/Excel Ver Feature
1.0 <= 5.6 <=7.0 ~2.1.0 using chunk() to handle big data
1.1 <= 5.6 <=7.0 ~2.1.0 using cursor() to handle big data
2.0 >= 5.5 ^7.0 ^3.1 Using new version of maatwebsite (v3.1)

Find the comparison between chunk and cursor in here

Installation

Add package to your composer:

composer require jimmyjs/laravel-report-generator

If you are running Laravel > 5.5 that's all you need to do. If you are using Laravel < 5.5 add the ServiceProvider to the providers array in config/app.php

Jimmyjs\ReportGenerator\ServiceProvider::class,

Optionally, you can add this to your aliases array in config/app.php

'PdfReport' => Jimmyjs\ReportGenerator\Facades\PdfReportFacade::class,
'ExcelReport' => Jimmyjs\ReportGenerator\Facades\ExcelReportFacade::class,
'CSVReport' => Jimmyjs\ReportGenerator\Facades\CSVReportFacade::class,

For more better speed on generating pdf report, I recommend you to use laravel snappy package. To using laravel snappy, you should install wkhtmltopdf to work with this package (Jump to wkhtmltopdf installation)

Example Display PDF Code

use PdfReport;

public function displayReport(Request $request)
{
    $fromDate = $request->input('from_date');
    $toDate = $request->input('to_date');
    $sortBy = $request->input('sort_by');

    $title = 'Registered User Report'; // Report title

    $meta = [ // For displaying filters description on header
        'Registered on' => $fromDate . ' To ' . $toDate,
        'Sort By' => $sortBy
    ];

    $queryBuilder = User::select(['name', 'balance', 'registered_at']) // Do some querying..
                        ->whereBetween('registered_at', [$fromDate, $toDate])
                        ->orderBy($sortBy);

    $columns = [ // Set Column to be displayed
        'Name' => 'name',
        'Registered At', // if no column_name specified, this will automatically seach for snake_case of column name (will be registered_at) column from query result
        'Total Balance' => 'balance',
        'Status' => function($result) { // You can do if statement or any action do you want inside this closure
            return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
        }
    ];

    // Generate Report with flexibility to manipulate column class even manipulate column value (using Carbon, etc).
    return PdfReport::of($title, $meta, $queryBuilder, $columns)
                    ->editColumn('Registered At', [ // Change column class or manipulate its data for displaying to report
                        'displayAs' => function($result) {
                            return $result->registered_at->format('d M Y');
                        },
                        'class' => 'left'
                    ])
                    ->editColumns(['Total Balance', 'Status'], [ // Mass edit column
                        'class' => 'right bold'
                    ])
                    ->showTotal([ // Used to sum all value on specified column on the last table (except using groupBy method). 'point' is a type for displaying total with a thousand separator
                        'Total Balance' => 'point' // if you want to show dollar sign ($) then use 'Total Balance' => '$'
                    ])
                    ->limit(20) // Limit record to be showed
                    ->stream(); // other available method: download('filename') to download pdf / make() that will producing DomPDF / SnappyPdf instance so you could do any other DomPDF / snappyPdf method such as stream() or download()
}

Note: For downloading to excel / CSV, just change PdfReport facade to ExcelReport / CSVReport facade with no more modifications

Data Manipulation

$columns = [
    'Name' => 'name',
    'Registered At' => 'registered_at',
    'Total Balance' => 'balance',
    'Status' => function($customer) { // You can do data manipulation, if statement or any action do you want inside this closure
        return ($customer->balance > 100000) ? 'Rich Man' : 'Normal Guy';
    }
];

Will produce a same result with:

$columns = [
    'Name' => function($customer) {
        return $customer->name;
    },
    'Registered At' => function($customer) {
        return $customer->registered_at;
    },
    'Total Balance' => function($customer) {
        return $customer->balance;
    },
    'Status' => function($customer) { // You can do if statement or any action do you want inside this closure
        return ($customer->balance > 100000) ? 'Rich Man' : 'Normal Guy';
    }
];

Report Output

Report Output with Grand Total

With this manipulation, you could do some eager loading relation like:

$post = Post::with('comments')->where('active', 1);

$columns = [
    'Post Title' => function($post) {
        return $post->title;
    },
    'Slug' => 'slug',
    'Latest Comment' => function($post) {
        return $post->comments->first()->body;
    }
];

Example Code With Group By

Or, you can total all records by group using groupBy method

    ...
    // Do some querying..
    $queryBuilder = User::select(['name', 'balance', 'registered_at'])
                        ->whereBetween('registered_at', [$fromDate, $toDate])
                        ->orderBy('registered_at', 'ASC'); // You should sort groupBy column to use groupBy() Method

    $columns = [ // Set Column to be displayed
        'Registered At' => 'registered_at',
        'Name' => 'name',
        'Total Balance' => 'balance',
        'Status' => function($result) { // You can do if statement or any action do you want inside this closure
            return ($result->balance > 100000) ? 'Rich Man' : 'Normal Guy';
        }
    ];

    return PdfReport::of($title, $meta, $queryBuilder, $columns)
                    ->editColumn('Registered At', [
                        'displayAs' => function($result) {
                            return $result->registered_at->format('d M Y');
                        }
                    ])
                    ->editColumn('Total Balance', [
                        'class' => 'right bold',
                        'displayAs' => function($result) {
                            return thousandSeparator($result->balance);
                        }
                    ])
                    ->editColumn('Status', [
                        'class' => 'right bold',
                    ])
                    ->groupBy('Registered At') // Show total of value on specific group. Used with showTotal() enabled.
                    ->showTotal([
                        'Total Balance' => 'point'
                    ])
                    ->stream();

PLEASE TAKE NOTE TO SORT GROUPBY COLUMN VIA QUERY FIRST TO USE THIS GROUP BY METHOD.

Output Report With Group By Registered At

Output Report with Group By Grand Total

Wkhtmltopdf Installation

  • Download wkhtmltopdf from https://wkhtmltopdf.org/downloads.html
  • Change your snappy config located in /config/snappy.php (run php artisan vendor:publish if snappy.php file is not created) to:
    'pdf' => array(
        'enabled' => true,
        'binary'  => '/usr/local/bin/wkhtmltopdf', // Or specified your custom wkhtmltopdf path
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

Other Method

1. setPaper($paper = 'a4')

Supported Media Type: PDF

Description: Set Paper Size

Params:

  • $paper (Default: 'a4')

Usage:

PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->setPaper('a6')
         ->make();

2. setCss(Array $styles)

Supported Media Type: PDF, Excel

Description: Set a new custom styles with given selector and style to apply

Params:

  • Array $styles (Key: $selector, Value: $style)

Usage:

ExcelReport::of($title, $meta, $queryBuilder, $columns)
            ->editColumn('Registered At', [
                'class' => 'right bolder italic-red'
            ])
            ->setCss([
                '.bolder' => 'font-weight: 800;',
                '.italic-red' => 'color: red;font-style: italic;'
            ])
            ->make();

3. setOrientation($orientation = 'portrait')

Supported Media Type: PDF

Description: Set Orientation to Landscape or Portrait

Params:

  • $orientation (Default: 'portrait')

Usage:

PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->setOrientation('landscape')
         ->make();

4. withoutManipulation()

Supported Media Type: PDF, Excel, CSV

Description: Faster generating report, but all columns properties must be matched the selected column from SQL Queries

Usage:

$queryBuilder = Customer::select(['name', 'age'])->get();
$columns = ['Name', 'Age'];
PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->withoutManipulation()
         ->make();

5. showMeta($value = true)

Supported Media Type: PDF, Excel, CSV

Description: Show / hide meta attribute on report

Params:

  • $value (Default: true)

Usage:

PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->showMeta(false) // Hide meta
         ->make();

6. showHeader($value = true)

Supported Media Type: PDF, Excel, CSV

Description: Show / hide column header on report

Params:

  • $value (Default: true)

Usage:

PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->showHeader(false) // Hide column header
         ->make();

7. showNumColumn($value = true)

Supported Media Type: PDF, Excel, CSV

Description: Show / hide number column on report

Params:

  • $value (Default: true)

Usage:

PdfReport::of($title, $meta, $queryBuilder, $columns)
         ->showNumColumn(false) // Hide number column
         ->make();

8. simple()

Supported Media Type: Excel

Description: Generate excel in simple mode (no styling on generated excel report, but faster in generating report)

Params:

  • None

Usage:

ExcelReport::of($title, $meta, $queryBuilder, $columns)
         ->simple()
         ->download('filename');
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].