PHP code example of jikerdev / simple-export

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

    

jikerdev / simple-export example snippets


use Jiker\SimpleExport\ExcelExport;

// 创建导出器
$exporter = new ExcelExport('data', 'Xlsx');

// 设置表头
$exporter->setHeader(['姓名', '年龄', '性别']);

// 添加数据到导出器
$data = [
    ['Tom', 20, '男'],
    ['Lucy', 18, '女'],
    ['Jack', 22, '男']
];
$exporter->appendData($data);

// 导出文件
$exporter->download();

// 创建导出器
$exporter = new ExcelExport('students', 'xlsx');
$exporter->setTitle('学生信息表');
$exporter->setTabName('成绩信息');
$exporter->setHeader(['姓名', '语文', '数学', '英语']);

// 添加数据到导出器
$data = [
    ['Tom', 85, 90, 93],
    ['Lucy', 94, 88, 91],
    ['Jack', 80, 72, 85]
];
$exporter->appendData($data);

// 导出文件
$exporter->download();

// 创建导出器
$exporter = new ExcelExport('data', 'csv');

// 添加数据到导出器
$data = [
    ['姓名', '年龄', '性别'],
    ['Tom', 20, '男'],
    ['Lucy', 18, '女'],
    ['Jack', 22, '男']
];
$exporter->appendData($data);

// 导出文件
$exporter->download();