PHP code example of denisristic / excel-service-provider

1. Go to this page and download the library: Download denisristic/excel-service-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

denisristic / excel-service-provider example snippets


        $excel = $app['excel']->generateXLSFromTable('tableName');

        $headers = array('ID', 'Name', 'Created');
        $data = array(
                0 => array('id' => 1, 'name' => 'Bill Gates', 'created' => '2015-01-01 00:00'),
                1 => array('id' => 2, 'name' => 'Steve Jobs', 'created' => '2015-01-02 00:00'),
                2 => array('id' => 3, 'name' => 'Bill Murray', 'created' => '2015-01-03 00:00')
        );

        $excel = $app['excel']->generateXLS($headers, $data);

        $controllers->get('/download', function () use($app) {
        
            $excel = $app['excel']->generateXLSFromTable('entry');

            $xlsName = 'entries-' . date('Y-m-dhis') . '.xls';
            $response = new Response($excel);
            $response->headers->add(array(
                'Content-Type' => 'application/vns.ms-excel'
                ,'Content-Disposition' => 'inline; filename="' . $xlsName . '"'
                ,'Pragma' => 'no-cache'
                ,'Expired' => 0
            ));
            return $response;
                
        })->bind('download');