承接 fersot/excel-to 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

fersot/excel-to

Composer 安装命令:

composer require fersot/excel-to

包简介

Laravel package that converts Excel/CSV files to JSON, Collection, or Array — with fluent API, sheet selection, column filtering, and export support.

README 文档

README

A Laravel package for converting Excel and CSV files to JSON, Laravel Collections, or PHP Arrays — with a fluent API, multi-sheet support, column filtering, date formatting, and export capabilities.

Latest Version PHP Version License Tests

Installation

composer require fersot/excel-to

Laravel auto-discovers the service provider and facade automatically.

Optionally publish the config file:

php artisan vendor:publish --tag=excel-to-config

Quick Start

use Fersot\ExcelTo\ExcelTo;

// Static shortcuts (backwards compatible)
$array      = ExcelTo::array('path/to/file.xlsx');
$collection = ExcelTo::collection('path/to/file.xlsx');
$json       = ExcelTo::json('path/to/file.xlsx');

// Fluent API (recommended)
$data = ExcelTo::file('path/to/file.xlsx')
    ->sheet('Clientes')
    ->skipEmpty()
    ->only(['nombre', 'email', 'ciudad'])
    ->dateFormat('Y-m-d')
    ->toArray();

Reading Files

Load from path

ExcelTo::file('path/to/file.xlsx')->toArray();

Load from Laravel UploadedFile

ExcelTo::upload($request->file('excel'))->toCollection();

Load a CSV

ExcelTo::file('path/to/file.csv')->toArray();

Output Formats

$instance = ExcelTo::file('file.xlsx');

$instance->toArray();       // PHP array
$instance->toCollection();  // Illuminate\Support\Collection
$instance->toJson();        // JSON string
$instance->toJson(JSON_PRETTY_PRINT); // JSON with flags

Fluent Options

All options can be chained in any order.

Select a Sheet

// By name
ExcelTo::file('file.xlsx')->sheet('Sheet2')->toArray();

// By zero-based index
ExcelTo::file('file.xlsx')->sheet(1)->toArray();

With a single-sheet file the result is a flat array. With multiple sheets, each sheet is a key in the result.

Skip Empty Rows

ExcelTo::file('file.xlsx')->skipEmpty()->toArray();

// Disable explicitly
ExcelTo::file('file.xlsx')->skipEmpty(false)->toArray();

Custom Header Row

Useful when the first row is a title and headers start on row 2:

ExcelTo::file('file.xlsx')->headerRow(2)->toArray();

Date Format

// Default: 'd/m/Y'
ExcelTo::file('file.xlsx')->dateFormat('Y-m-d')->toArray();
ExcelTo::file('file.xlsx')->dateFormat('d-m-Y H:i')->toArray();

Filter Columns

// Keep only these columns
ExcelTo::file('file.xlsx')->only(['nombre', 'email'])->toArray();

// Exclude these columns
ExcelTo::file('file.xlsx')->except(['id', 'internal_code'])->toArray();

Exporting to Excel

use Fersot\ExcelTo\ExcelTo;

$data = [
    ['producto' => 'Widget', 'precio' => 9.99,  'stock' => 100],
    ['producto' => 'Gadget', 'precio' => 19.99, 'stock' => 50],
];

ExcelTo::fromArray($data)->export('storage/exports/report.xlsx');

// From a Collection
ExcelTo::fromCollection($collection)->export('storage/exports/report.xlsx');

Configuration

After publishing, edit config/excel-to.php:

return [
    'date_format' => 'd/m/Y',   // Default date output format
    'skip_empty'  => false,     // Skip empty rows by default
    'header_row'  => 1,         // Default header row number
];

Options set via the fluent API always override config values.

Full Example

use Fersot\ExcelTo\ExcelTo;

$report = ExcelTo::file(storage_path('imports/ventas_2024.xlsx'))
    ->sheet('Enero')
    ->headerRow(2)
    ->skipEmpty()
    ->only(['cliente', 'importe', 'fecha'])
    ->dateFormat('Y-m-d')
    ->toCollection();

$report->each(fn($row) => \Log::info($row));

Requirements

Dependency Version
PHP ^8.1
Laravel ^9.0 | ^10.0 | ^11.0 | ^12.0
PhpSpreadsheet ^1.29 | ^2.0

Testing

composer install
./vendor/bin/phpunit --testdox

25 tests covering all features.

Author

Hember Colmenareshemberfer@gmail.com · GitHub

Support Me ☕️

If you find this package useful, consider buying me a coffee.

Buy Me a Coffee

License

MIT — see LICENSE.

fersot/excel-to 适用场景与选型建议

fersot/excel-to 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「json」 「excel」 「spreadsheet」 「xlsx」 「csv」 「export」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 fersot/excel-to 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 fersot/excel-to 我们能提供哪些服务?
定制开发 / 二次开发

基于 fersot/excel-to 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-13