2017 © Pedro Peláez
 

library data-table

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

image

kedrigern/data-table

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

  • Tuesday, March 14, 2017
  • by Kedrigern
  • Repository
  • 2 Watchers
  • 2 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Data table

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

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

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

Build Status, (*4)

Install

The best way how to install is use Composer:, (*5)

php composer.phar require kedrigern/data-table

Run tests: vendor/bin/tester -c test/ test/, (*6)

Examples

Suppose:, (*7)

$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:, (*8)

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:, (*9)

$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., (*10)

Remove if

Remove all rows with even number in first column:, (*11)

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

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

In removed are number of modified rows., (*12)

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"], (*13)

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"]., (*14)

Or opposite way:, (*15)

$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, (*16)

Author and contact

The Versions

14/03 2017

dev-master

9999999-dev https://github.com/Kedrigern/data-table

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

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

 

The Development Requires

csv array table data spreadsheet column row

05/09 2014

v1.0

1.0.0.0 https://github.com/Kedrigern/data-table

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

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

 

The Development Requires

csv array table data spreadsheet column row

15/08 2014

v0.9

0.9.0.0 https://github.com/Kedrigern/data-table

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

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

csv array table data spreadsheet column row

07/08 2014

v0.8

0.8.0.0 https://github.com/Kedrigern/data-table

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

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

csv array table data spreadsheet column row

21/07 2014

v0.7

0.7.0.0 https://github.com/Kedrigern/

Manipulation with table organized collection of data.

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

csv array table data spreadsheet column row

19/07 2014

v0.5

0.5.0.0 https://github.com/Kedrigern/

Manipulation with table organized collection of data.

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

csv array table data spreadsheet column row

19/07 2014

v0.6

0.6.0.0 https://github.com/Kedrigern/

Manipulation with table organized collection of data.

  Sources   Download

GPL-3.0 BSD-3-Clause

The Requires

  • php >=5.3.0

 

The Development Requires

csv array table data spreadsheet column row