定制 slam/php-excel 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slam/php-excel

最新稳定版本:v5.1.0

Composer 安装命令:

composer require slam/php-excel

包简介

Old faster PHPExcel

README 文档

README

Slam PHPExcel old&faster

Latest Stable Version Downloads Integrate Code Coverage

This package is NOT intended to be complete and flexible, but to be fast.

PHPOffice/PHPExcel and PHPOffice/PhpSpreadsheet are great libraries, but abstract everything in memory before writing to the disk. This is extremely inefficent and slow if you need to write a giant XLS with thousands rows and hundreds columns.

Based on Spreadsheet_Excel_Writer v0.9.3, which can be found active on Github. This is not a fork: I copied it and adapted to work with PHP 7.1 and applied some coding standard fixes and some Scrutinizer patches.

Installation

composer require slam/php-excel

Usage

From version 4 the code is split in two parts:

  1. Slam\Excel\Pear namespace, the original Pear code
  2. Slam\Excel\Helper namespace, an helper to apply a trivial style on a Table structure:
use Slam\Excel\Helper as ExcelHelper;

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

// Being an Iterator, the data can be any dinamically generated content
// for example a PDOStatement set on unbuffered query
$users = new ArrayIterator([
    [
        'column_1' => 'John',
        'column_2' => '123.45',
        'column_3' => '2017-05-08',
    ],
    [
        'column_1' => 'Mary',
        'column_2' => '4321.09',
        'column_3' => '2018-05-08',
    ],
]);

$columnCollection = new ExcelHelper\ColumnCollection([
    new ExcelHelper\Column('column_1',  'User',     10,     new ExcelHelper\CellStyle\Text()),
    new ExcelHelper\Column('column_2',  'Amount',   15,     new ExcelHelper\CellStyle\Amount()),
    new ExcelHelper\Column('column_3',  'Date',     15,     new ExcelHelper\CellStyle\Date()),
]);

$filename = sprintf('%s/my_excel_%s.xls', __DIR__, uniqid());

$phpExcel = new ExcelHelper\TableWorkbook($filename);
$worksheet = $phpExcel->addWorksheet('My Users');

$table = new ExcelHelper\Table($worksheet, 0, 0, 'My Heading', $users);
$table->setColumnCollection($columnCollection);

$phpExcel->writeTable($table);
$phpExcel->close();

Result:

Example

统计信息

  • 总下载量: 38.18k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-16