PHP code example of lfphp / xlsxbuilder

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

    

lfphp / xlsxbuilder example snippets


//设置列格式
$header_types = array(
   'created'=>'date',
   'product_id'=>'string',
   'quantity'=>'#,##0',
   'amount'=>'price',
   'description'=>'string',
   'tax'=>'[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00',
);
//数据
$data = array(
   array('2015-01-01',874234242342343,1,'44.00','misc','=D2*0.05'),
   array('2015-01-12',324,2,'88.00','none','=D3*0.05'),
);

$writer = new XLSXBuilder();
$sheet = $writer->createSheet('Sheet1'); //创建工作表 Sheet1
$sheet->setHeader($header_types);
foreach($data as $row){
   $writer->getSheet('Sheet1')->writeRow($row);
}
$writer->saveAs('example.xlsx');