parkejunior/spreadsheetmr
Composer 安装命令:
composer require parkejunior/spreadsheetmr
包简介
Multiformat spreadsheet reader
README 文档
README
SpreadSheetMR is a simple multiformat spreadsheet reader.
- Read XLSX, XLS, CSV or TXT files
- Combine header with data
- Ignore row or columns
This library uses shuchkin/SimpleXLS and shuchkin/SimpleXLSX for read Excel files.
Installation
First, you will need to install Composer. Then, run the following command:
$ composer install parkejunior/spreadsheetmr
Usage
Basic
Here is a basic example of using the library:
use SpreadSheetMR\SpreadSheetMR; $path_to_file = "file.csv"; $file_extension = ".csv"; // or only "csv" $import = new SpreadSheetMR($path_to_file, $file_extension); $data = $import->getObject(); var_dump($data);
The getObject method get data formatted using stdClass.
Note that the file extension is passed as a separate property from the file path, because the path can be temporary like the superglobal $_FILES['file']['tmp_name'].
Verify header and limits
You can use the verifyFile() method by passing an array with some settings. Example:
... $import->verifyFile(array( "first_title" => "name", // check if first title on header is "name" "last_title" => "phone", // check if last title on header is "phone" "total_columns" => 4 // check if total columns on header is 4 )); $data = $import->getObject(); var_dump($data);
Ignore row and columns
It is also possible to ignore columns or rows using the ignoreRow() and ignoreColumn() methods by passing the index offset as a parameter. Example:
... $import->ignoreRow(3); // ignore 4th row $import->ignoreColumn(0); // ignore first column $data = $import->getObject(); var_dump($data);
Define which row is the header
You can define which line is the header by passing to the headerIndex property the index offset of the line. Note that when the header is defined, the getObject () method returns a stdClass combining the header as an association to the data of each line. Example:
... $import->headerIndex = 0; // define first row as header $data = $import->getObject(); var_dump($data);
Contribution
If you find any incorrect English grammar or any suggestions on how to improve the library, I appreciate it.
parkejunior/spreadsheetmr 适用场景与选型建议
parkejunior/spreadsheetmr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 parkejunior/spreadsheetmr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 parkejunior/spreadsheetmr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-12