PHP code example of easy-excel / polyfill

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

    

easy-excel / polyfill example snippets


use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

// style first, then bulk-write: everything below streams at constant memory
$sheet->getStyle('A1:C1')->applyFromArray([
    'font' => ['bold' => true, 'color' => ['rgb' => 'FFFFFF']],
    'fill' => ['fillType' => 'solid', 'startColor' => ['rgb' => '4472C4']],
]);
$sheet->getStyle('B2:B100000')->getNumberFormat()->setFormatCode('#,##0.00');
$sheet->getColumnDimension('A')->setWidth(28);
$sheet->freezePane('A2');

$sheet->fromArray($hugeDataset);          // batched straight into Go
$sheet->setAutoFilter('A1:C100000');      // injected at save, still streaming

IOFactory::createWriter($spreadsheet, 'Xlsx')->save('report.xlsx');
$spreadsheet->disconnectWorksheets();     // frees the native workbook