承接 kedrigern/data-table 相关项目开发

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

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

kedrigern/data-table

Composer 安装命令:

composer require kedrigern/data-table

包简介

Manipulation with table organized collection of data (csv, excel). Contains functions for work with whole columns, rows, filtering etc.

README 文档

README

#Data table

For robust manipulation with table organized collection of data (excel, csv tables).

Provide ability to work with whole rows and columns, call callbacks, resort, rename, filter. Include few predefined callbacks. See examples.

Import csv and array. Export to plain array, text, html, csv. Export is suitable for DB frameworks (Nette\Database).

Build Status

##Install

The best way how to install is use Composer:

php composer.phar require kedrigern/data-table

Run tests: vendor/bin/tester -c test/ test/

##Examples

Suppose:

$table = new \Kedrigern\DataTable\RecordTable();
$table->loadFromArray(array(
	array("Name", "Surname", "Age"),
	array("Jane", "Roe", 29),
	array("John", "Doe", 30)
));
$table->useFirstRowAsHeader();

// Sum the ages = 59
$ageSum = $table->colSum("Age");

$table->sortByCol("Surname");
$table->callToCol("Surname", 'strtoupper');

$newCol = range(1,$table->getRowsNum());
$table->appendCol($newCol, "Unique");

$newTable = $table->resortColsByNewHeader(array("Unique", "Surname", "Name"));

$newTable contains:

1 DOE John
2 ROE Jane

CSV with header

Very common issue when you have some data in csv with header and you need only subset:

$table->loadFromCsvFile(__DIR__ . '/../data/data4.csv');
$table->useFirstRowAsHeader();

$map = array(
	"Alpha" => "A",
	"Beta" => "B",
);

$table2 = $table->renameColumns($map);

Where table2 contains column Alpha renamed to A and column Beta renamed to B. See test.

Remove if

Remove all rows with even number in first column:

$isEven = function($row) {
  return ($row[0] % 2) == 0;
};

$removed = $t->removeRowsIf($isEven);

In removed are number of modified rows.

Parse datetime

$table->loadFromArray(array(
	array("Name", "Surname", "Age", "Born", "Registered"),
	array("Jane", "Roe", 29, "1990-1-1", "2013-12-30 01:02:03"),
	array("John", "Doe", 30, "1990-1-1", "2014-12-30 01:02:03")
));
$table->useFirstRowAsHeader();

$func = array('\Kedrigern\DataTable\Callback','toDatetime');

$table->callToCol(3, $func, array('Y-m-d', 'M y'));
$table->callToCol(4, $func, array('Y-m-d H:i:s', 'U', 'Europe/London'));

Now Born seems: ["Jan 90", "Feb 91"], and registered: ["1388361723", "1419897723"]

Join and split columns

$table->loadFromArray(array(
	array("Name", "Surname"),
	array("Jane", "Roe"),
	array("John", "Doe")
));

$table->joinCols(["Name", "Surname"], "Fullname");

In Fullname column you get: ["Jane Roe", "John Doe"].

Or opposite way:

$table->loadFromArray(array(
	array("Fullname"),
	array("Jane Roe"),
	array("John Doe")
));

$table->splitCol("Fullname", ["Name", "Surname"]);

Callbacks

Predefined callbacks:

  • join
  • joinWith
  • split
  • toDatetime
  • isEven
  • isOdd
  • allowValues
  • disallowValues
  • unicodeTrim

##Author and contact

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-07-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固