PHP code example of sulabh / excel-file-package

1. Go to this page and download the library: Download sulabh/excel-file-package 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/ */

    

sulabh / excel-file-package example snippets




use Sulabh\ExcelFilePackage\ExcelFile;
use App\Model\User;

// data to be exported, supported format is Laravel's Model.
// You can filter the data as per your need using where conditions;
$data = User::query();

// Number of data you want in a Single Sheet. 
// 1 Excel Sheet can store upto 1,048,576 rows, 
// so this value should not exceed 1,048,575. 
// 1 is for header
$chunk_size = 100000;

// List of headers in each column respectively
$header = ['S.No', 'Name', 'Email', 'Phone Number'];

// No need to use .xlsx, even if entered its filtered by the package
$file_name = "UsersExport";

// Define how the data in export should be displayed
$row_formatter = function($row) {
  return [
    'SERIAL_NO', // This is a wildcard and represents an incremental value, It starts with 1 in every sheet
    $row->first_name." ".$row->last_name,
    $row->email,
    $row->phone_number,
  ];
};

// Optional
$total_count = $data->count();

ExcelFile::createExcelFile($data, $chunk_size, $header, $file_name, $row_formatter, $total_data);