PHP code example of wilsonglasser / spout

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

    

wilsonglasser / spout example snippets


$worksheet = $writer->getCurrentSheet();
$worksheet->mergeCells('A1:B1');

$rowStyle = (new StyleBuilder())
    ->setFontSize(10)
    ->setFontName('Arial')
    ->setRowHeight(50)
    ->build();
$writer->addRow(new Row([new Cell('Hello World')], $rowStyle));

// Specific size
$worksheet->addColumnDimension(
    new ColumnDimension('A', 50 )
);

// Autosize 
$worksheet->addColumnDimension(new ColumnDimension(
    'A',
    -1,
    true
));

$worksheet = $writer->getCurrentSheet();
$worksheet->setAutoFilter('A1:Z1');

$Cell = new Cell('=A1', null);
$Cell->setCalculatedValue('100.00');

$originalValue = 100.0;
$value = 'R$'.number_format($originalValue, 2,',','.');
$style = (new StyleBuilder())
        ->setFontSize(10)
        ->setFontName('Arial')
        ->setNumberFormat(new NumberFormat('0 - "' . $value . '"'))
        ->build();
$Cell = new Cell($value, $style);
// date
$styleMonthYear =  (new StyleBuilder())
    ->setFontSize(10)
    ->setFontName('Arial')
    ->setNumberFormat(new NumberFormat('MM/YYYY'))
    ->build();

$worksheet = $writer->getCurrentSheet();
$worksheet->addComment(
    new Comment('A1', 'My comment', 'Comment user, null for nothing')
);

// echo 0
echo CellHelper::getColumnToIndexFromCellIndex('A1');