PHP code example of ajur-media / xlsx-writer

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

    

ajur-media / xlsx-writer example snippets


$data = [
    ['year','month','amount'],
    ['2003','1','220'],
    ['2003','2','153.5'],
];

$writer = new XLSXWriter();
$writer->writeSheet($data);
$writer->writeToFile('output.xlsx');

$header = [
  'created'=>'date',
  'product_id'=>'integer',
  'quantity'=>'#,##0',
  'amount'=>'price',
  'description'=>'string',
  'tax'=>'[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00',
];
$data = [
    ['2015-01-01',873,1,'44.00','misc','=D2*0.05'],
    ['2015-01-12',324,2,'88.00','none','=D3*0.05'],
];

$writer = new XLSXWriter();
$writer->writeSheetHeader('Sheet1', $header );
foreach($data as $row)
	$writer->writeSheetRow('Sheet1', $row );
$writer->writeToFile('example.xlsx');

$writer = new XLSXWriter();
$writer->writeSheetHeader('Sheet1', ['c1'=>'integer','c2'=>'integer','c3'=>'integer','c4'=>'integer'] );
for($i=0; $i<50000; $i++)
{
    $writer->writeSheetRow('Sheet1', [$i, $i+1, $i+2, $i+3] );
}
$writer->writeToFile('huge.xlsx');
echo '#'.floor((memory_get_peak_usage())/1024/1024)."MB"."\n";