PHP code example of avadim / fast-excel-writer

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

    

avadim / fast-excel-writer example snippets


use \avadim\FastExcelWriter\Excel;
use \avadim\FastExcelWriter\Style\Style;

$data = [
    ['2003-12-31', 'James', '220'],
    ['2003-8-23', 'Mike', '153.5'],
    ['2003-06-01', 'John', '34.12'],
];

$excel = Excel::create(['Sheet1']);
$sheet = $excel->sheet();

// Write the head row and set styles via fluent interface
$sheet->writeHeader(['Date', 'Name', 'Amount'])
    ->applyFontStyleBold()
    ->applyBorder(Style::BORDER_STYLE_THIN);

// Set column formats and widths
$sheet
    ->setColFormats(['@date', '@text', '0.00'])
    ->setColWidths([12, 14, 8]);

// Write data
foreach ($data as $rowData) {
    $sheet->writeRow($rowData);
}

// Save to a file
$excel->save('simple.xlsx');

// ...or download generated file to client (send to browser)
// $excel->download('simple.xlsx');