从 Laravel 集合生成 Excel 表格

0.1.0 2019-03-12 07:28 UTC

This package is auto-updated.

Last update: 2024-09-12 20:29:07 UTC


README

此包封装了 PHP Office Spreadsheet,用于从 Laravel 集合生成 Excel 表格。

入门指南

使用 composer 安装此包

$ composer require waxwink/report

说明

以下是一个使用此包的示例

use Illuminate\Support\Collection;
use Waxwink\Report\Excel;

require __DIR__."/vendor/autoload.php";

$keys = [
    'id'=> 'Product ID',
    'name'=> 'Name',
    'price'=> 'Price',
];

$collection = new Collection([
    [
        'id'=> '1574',
        'name'=> 'Phone',
        'price'=> '100',],
    [
        'id'=> '6541',
        'name'=> 'Printer',
        'price'=> '150',
    ],
    [
        'id'=> '9652',
        'name'=> 'Laptop',
        'price'=> '350',
    ],
    [
        'id'=> '6971',
        'name'=> 'Mouse',
        'price'=> '30',
    ]
]);

$xl = new Excel($collection, $keys);

//this would save the file in the root folder : table.xlsx
$xl->export('table');

您也可以将文件发送给客户下载。

// (works only if you're using laravel)
return response()->download($xl->update());