atk14/csv-writer
Composer 安装命令:
composer require atk14/csv-writer
包简介
Writes CSV into string output or a file. Also provides export to XLSX format.
README 文档
README
Writes CSV into string output or a file. Also provides export to XLSX format.
Basic usage
$writer = new CsvWriter([
"delimiter" => ";",
"quote" => '"',
"escape_char" => "\\",
]);
$writer->addRow([
"product_no" => "CAN_G1X",
"price" => 4999.0,
]);
$writer->addRow([
"product_no" => "CAN_G15",
"price" => 2099.99,
]);
echo $writer->writeToString();
// CAN_G1X;4999
// CAN_G15;2099.99
echo $writer->writeToString(["with_header" => true]);
// product_no;price
// CAN_G1X;4999
// CAN_G15;2099.99
echo $writer->writeToString(["with_header" => ["Product No.","Price"]]);
// "Product No.";Price
// CAN_G1X;4999
// CAN_G15;2099.99
The header can be added automatically with the "with_header" option set to "auto":
$writer = new CsvWriter();
$writer->addRow(["k1" => "v1", "k2" => "v2"]);
echo $writer->writeToString(["with_header" => "auto"]);
// k1;k2
// v2;v2
$writer = new CsvWriter();
$writer->addRow(["v1","v2"]);
echo $writer->writeToString(["with_header" => "auto"]);
// v2;v2
CsvWriter implements ArrayAccess for easier rows adding:
$writer[] = ["k1" => "v1","k2" => "v2"];
$writer[] = ["k1" => "v3","k2" => "v4"];
XLSX format
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=data.xlsx");
echo $writer->writeToString(["format" => "xlsx"]);
Export to a file
$writer->writeToFile("/path/to/a/file.csv",["with_header" => true]);
$writer->writeToFile("/path/to/a/file.xlsx",["with_header" => true, "format" => "xlsx"]);
Special options
In case of exporting to CSV, the BOM sequence is automatically written at the beginning of the file. It can be disabled by the options write_bom set to false.
$write->writeToFile("/path/to/a/file.csv",[
"format" => "csv",
"write_bom" => false
]);
Sheet name can be set for XLSX export.
$write->writeToFile("/path/to/a/file.xlsx",[
"format" => "xlsx",
"sheet_name" => "Order history"
]);
Installation
composer require atk14/cvs-writer
Testing
composer update --dev
./vendor/bin/run_unit_tests test
License
CsvWriter is free software distributed under the terms of the MIT license
atk14/csv-writer 适用场景与选型建议
atk14/csv-writer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17.51k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 10 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「xls」 「xlsx」 「csv」 「export」 「writer」 「exporter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atk14/csv-writer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atk14/csv-writer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atk14/csv-writer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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
laravel facade to read/write csv file
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Collection of tools to use the full power of the Enyalius framework
统计信息
- 总下载量: 17.51k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-10-09