elton182/spreadsheet
Composer 安装命令:
composer require elton182/spreadsheet
包简介
Spreadsheet reader library for Excel, OpenOffice and structured text files, compatible with cakephp3
README 文档
README
This is a fork from (https://github.com/nuovo/spreadsheet-reader). I made this fork so i could make it compatible with cakephp3 and psr-4.
spreadsheet-reader is a PHP spreadsheet reader that differs from others in that the main goal for it was efficient data extraction that could handle large (as in really large) files. So far it may not definitely be CPU, time or I/O-efficient but at least it won't run out of memory (except maybe for XLS files).
So far XLSX, ODS and text/CSV file parsing should be memory-efficient. XLS file parsing is done with php-excel-reader from http://code.google.com/p/php-excel-reader/ which, sadly, has memory issues with bigger spreadsheets, as it reads the data all at once and keeps it all in memory.
Requirements:
- PHP 5.3.0 or newer
- PHP must have Zip file support (see http://php.net/manual/en/zip.installation.php)
Usage on Cakephp Controller:
<?php
namespace App\Controller;
use App\Controller\AppController;
use elton182\spreadsheet\SpreadsheetReader;
class ExcelController extends AppController
{
public function index(){
if($this->request->is('post')){
$arquivo = $this->request->data['uploadfile'][0]['tmp_name'];
$nome = $this->request->data['uploadfile'][0]['name'];
$Reader = new SpreadsheetReader($arquivo,$nome);
foreach ($Reader as $Row)
{
print_r($Row);
}
}
}
}
?>
Usage:
All data is read from the file sequentially, with each row being returned as a numeric array. This is about the easiest way to read a file:
<?php
// If you need to parse XLS files, include php-excel-reader
require('php-excel-reader/excel_reader2.php');
require('SpreadsheetReader.php');
$Reader = new SpreadsheetReader('example.xlsx');
foreach ($Reader as $Row)
{
print_r($Row);
}
?>
However, now also multiple sheet reading is supported for file formats where it is possible. (In case of CSV, it is handled as if it only has one sheet.)
You can retrieve information about sheets contained in the file by calling the Sheets() method which returns an array with
sheet indexes as keys and sheet names as values. Then you can change the sheet that's currently being read by passing that index
to the ChangeSheet($Index) method.
Example:
<?php
$Reader = new SpreadsheetReader('example.xlsx');
$Sheets = $Reader -> Sheets();
foreach ($Sheets as $Index => $Name)
{
echo 'Sheet #'.$Index.': '.$Name;
$Reader -> ChangeSheet($Index);
foreach ($Reader as $Row)
{
print_r($Row);
}
}
?>
If a sheet is changed to the same that is currently open, the position in the file still reverts to the beginning, so as to conform to the same behavior as when changed to a different sheet.
Testing
From the command line:
php test.php path-to-spreadsheet.xls
In the browser:
http://path-to-library/test.php?File=/path/to/spreadsheet.xls
Licensing
All of the code in this library is licensed under the MIT license as included in the LICENSE file, however, for now the library relies on php-excel-reader library for XLS file parsing which is licensed under the PHP license.
elton182/spreadsheet 适用场景与选型建议
elton182/spreadsheet 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 01 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「excel」 「spreadsheet」 「xls」 「xlsx」 「csv」 「OpenOffice」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elton182/spreadsheet 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elton182/spreadsheet 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elton182/spreadsheet 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This Symfony bundle integrates PhpSpreadsheet into Symfony using Twig.
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Yii2 export extension
PHP Excel Library
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
统计信息
- 总下载量: 53
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-26