PHP code example of mistericy / excel-writer

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

    

mistericy / excel-writer example snippets


//Create a generator
$generator = new BasicGenerator();

//Add handlers to the generator
$generator
    ->setHandler(new MetadataHandler())
    ->setNext(new FormatHandler())
    ->setNext(new DataHandler());

//Create a property collection
$properties = new PropertyCollection();

//Create a simple index Property
$properties->addProperty(
    PropertyBuilder::createProperty(IntProperty::class, null, true, '={row}-1')
        ->setTitle('id')
    )
    ->addProperty(
        PropertyBuilder::createProperty(StringProperty::class, 'name')
            ->setTitle('name')
            ->setWidth(30)
        )
    ->addProperty(
        PropertyBuilder::createProperty(IntProperty::class, 'age')
            ->setTitle('age')
            ->setWidth(15)
            ->setCallable(function($d) { return ($d<18) ? 'N/A': $d; })
        );    
//Generate the writer

$writer = ExcelWriter::createWriter($generator, $properties);
/* Get your data in $data (array of objects) */
$data = $this->getData();

$file = $writer->generateFile($data, $filename);