k9606/kxcel

Easy to import and export excel.

v1.0.2 2020-08-20 06:50 UTC

This package is auto-updated.

Last update: 2021-05-20 08:35:53 UTC


README

方便导入和导出 excel.

安装

$ composer require k9606/kxcel

使用

  • 导出
use K9606\Kxcel\Kxcel;

$sourceDatas = [
    [
        'id' => 1,
        'name' => '黄蜂女',
        'gender' => '女',
        'specialty' => '变化',
        'address' => '新泽西',
        'professional' => '复联成员',
    ],
    [
        'id' => 2,
        'name' => 'k9606',
        'gender' => '男',
        'specialty' => '无',
        'address' => '天府新区',
        'professional' => '复联成员',
    ],
    [
        'id' => 3,
        'name' => '蜘蛛侠',
        'gender' => '男',
        'specialty' => '灵敏',
        'address' => '皇后区',
        'professional' => '复联成员',
    ],
];

$sourceDataKeysAndColumnNames = [
    'name' => '姓名',
    'gender' => '性别',
    'address' => '所在地',
];

$fileName = 'excel';

$kxcel = new Kxcel();
$kxcel->export($sourceDatas, $sourceDataKeysAndColumnNames, $fileName);
请求:
参数 必选 类型 注释
$sourceDatas true array 源数据
$sourceDataKeysAndColumnNames true array 列值在 $sourceDatas 对应键与列名, 例如 ['name' => '姓名']
$fileName false string 待导出的文件名, 默认为 'excel'
响应:

导出结果预览

  • 导入
use K9606\Kxcel\Kxcel;

$filePath = './kxcel.xlsx';

$x = ['B' => 2];
$y = ['C' => 3];

$kxcel = new Kxcel();
$kxcel->import($filePath, $x, $y);
请求:
参数 必选 类型 注释
$filePath true string excel 文件路径
$x true array 开始读取点的列与行坐标, [ 列 => 行 ]
$y true array 结束读取点的列与行坐标, 同上
响应:
[
    [
        "女",
        "新泽西"
    ],
    [
        "男",
        "天府新区"
    ]
]

基于

PHPOffice/PhpSpreadsheet

overtrue/package-builder

License

MIT