PHP code example of tianhe1986 / fatexcel

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

    

tianhe1986 / fatexcel example snippets




use FatExcel\FatExcel;

$fatExcel = new FatExcel();

$data = $fatExcel->importToArray('/path/to/excel');

use FatExcel\FatExcel;

$fatExcel = new FatExcel();

$data = [
    [1, 2, 3, 4, 5],
    [6, 7, 8, 9, 10]
];

//导出到文件
$fatExcel->exportToFile($data, '/path/to/excel');

//直接下载
$excel->exportDownload($data, '666.xlsx');

use FatExcel\FatExcel;

$fatExcel = new FatExcel();

$header = [
    'created' => 'date',
    'product_id' => 'integer',
    'quantity' => '#,##0',
    'amount' => 'price',
    'total' => '0.00E+00',
    'code' => 'string',
    'tax' => '[$$-1009]#,##0.00;[RED]-[$$-1009]#,##0.00',
];

$data = [
    ['2015-01-01', 873, 1, '44.00', 99909, '12345678900000000', '=D2*0.05'],
    ['2015-01-12', 324, 2, '88.00', 10000, '12345678911111111','=D3*0.05'],
];

//导出到文件
$fatExcel->exportToFile($data, '/path/to/excel', $header);

//直接下载
$fatExcel->exportDownload($data, '开不了机让她知道.xlsx', $header);