PHP code example of slam / openspout-helper

1. Go to this page and download the library: Download slam/openspout-helper 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/ */

    

slam / openspout-helper example snippets


use OpenSpout\Writer\Common\Creator\WriterEntityFactory;
use Slam\OpenspoutHelper as ExcelHelper;

ment set on unbuffered query
$users = [
    [
        'column_1' => 'John',
        'column_2' => '123.45',
        'column_3' => '2017-05-08',
    ],
    [
        'column_1' => 'Mary',
        'column_2' => '4321.09',
        'column_3' => '2018-05-08',
    ],
];

$columnCollection = new ExcelHelper\ColumnCollection(...[
    new ExcelHelper\Column('column_1',  'User',     10,     new ExcelHelper\CellStyle\Text()),
    new ExcelHelper\Column('column_2',  'Amount',   15,     new ExcelHelper\CellStyle\Amount()),
    new ExcelHelper\Column('column_3',  'Date',     15,     new ExcelHelper\CellStyle\Date()),
]);

$XLSXWriter  = WriterEntityFactory::createXLSXWriter();
$XLSXWriter->openToFile(__DIR__.'/test.xlsx');

$activeSheet = $XLSXWriter->getCurrentSheet();
$activeSheet->setName('My Users');
$table = new ExcelHelper\Table($activeSheet, 'My Heading', $users);
$table->setColumnCollection($columnCollection);

(new ExcelHelper\TableWriter())->writeTable($XLSXWriter, $table);
$XLSXWriter->close();