定制 spyck/spreadsheet 二次开发

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

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

spyck/spreadsheet

最新稳定版本:1.0.6

Composer 安装命令:

composer require spyck/spreadsheet

包简介

Simple PHP tool for parsing CSV or Excel spreadsheets

README 文档

README

Simple tool for parsing CSV or Excel spreadsheets, with the possibility to filter rows.

Requirements

PHP ^8.2

Installation

Install it using Composer:

composer require spyck/spreadsheet

Example usage

<?php
 
declare(strict_types=1);

use Spyck\Spreadsheet\Csv;

require 'vendor/autoload.php';

/**
 * Content of test.csv.gz
 * 
 * name;count
 * apple;15
 * banana;20
 * pear;10
 * melon;4
 */

$csv = new Csv();
$csv->setGzip(true);
$csv->setFilter(function (array $data): bool {
    return $data['count'] > 10;
});

$result = $csv->getResult('test.csv.gz', [
    'name',
    'count',
]);

print_r ($result->getData());

/**
 * Result:
 * 
 * [
 *    'name' => 'apple',
 *    'count' => '15',
 * ],
 * [
 *    'name' => 'banana',
 *    'count' => '20',
 * ];
 */

$csv = new Csv();
$csv->setGzip(true);
$csv->setCallback(function (array $data): ?array {
    $data['name'] = ucfirst($data['name']);
    
    return $data;
});
$csv->setFilter(function (array $data): bool {
    return $data['count'] > 10;
});

$result = $csv->getResult('test.csv.gz', [
    'name',
    'count',
]);

print_r ($result->getData());

/**
 * Result:
 * 
 * [
 *    'name' => 'Apple',
 *    'count' => '15',
 * ],
 * [
 *    'name' => 'Banana',
 *    'count' => '20',
 * ];
 */
 
$csv = new Csv();
$csv->setGzip(true);
$csv->setEof(function (array $data, int $index): bool {
    return 'banana' === $data['name'];
});

$result = $csv->getResult('test.csv.gz', [
    'name',
    'count',
]);

print_r ($result->getData());

/**
 * Result:
 * 
 * [
 *    'name' => 'apple',
 *    'count' => '15',
 * ];
 */

print $result->getTotal();

/**
* Result:
 * 
 * 1
 */

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-19