PHPackages                             nagyatka/tableconverter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. nagyatka/tableconverter

ActiveLibrary[Database &amp; ORM](/categories/database)

nagyatka/tableconverter
=======================

Table format converter

v1.0.7(5y ago)181↓100%Apache-2.0PHPCI failing

Since Jan 29Pushed 5y ago2 watchersCompare

[ Source](https://github.com/nagyatka/TableConverter)[ Packagist](https://packagist.org/packages/nagyatka/tableconverter)[ Docs](https://github.com/nagyatka/tableconverter)[ RSS](/packages/nagyatka-tableconverter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (3)Versions (9)Used By (0)

User documentation
==================

[](#user-documentation)

To convert a table to another format you have to define 3 parameters:

- A decoder which tries to decode the original format
- A coder which will generate the new table
- An association rule which helps the converter to make an appropriate conversion

```
Converter::convert(Decoder $decoder, AssociationRule $associationRule, Coder $coder);
```

\##Simple examples

It inserts an xlsx file to mysql table using mysqli. It will use the xls header as column names of the mysql table:

```
Converter::convert(new XlsxCodec("test_file.xlsx"), new SimpleAssociationRule(), new MysqliCodec($connection,"table_name"));
```

It inserts an php array to mysql table using mysqli. It will use the array keys as column names of the mysql table:

```
$testArray = [
    ["col1" => 2, "col2" => 3, "col3" => "yes"],
    ["col1" => 1, "col2" => 222, "col3" => "apple"],
];
Converter::convert(new ArrayCodec($testArray), new SimpleAssociationRule(), new MysqliCodec($connection,"table_name"));
```

\##Codecs

Codec classes contain the coder and decoder implementation for an appropriate format.

**ArrayCodec**

```
$testArray = [
    ["col1" => 2, "col2" => 3, "col3" => "yes"],
    ["col1" => 1, "col2" => 222, "col3" => "apple"],
];

//If you use ArrayCodec as Decoder you have to specify the input associative array.
$arrayDecoder = new ArrayCodec($testArray);

//If you use ArrayCodec as Coder you can leave the constructor blank.
$arrayCoder = new ArrayCodec();
```

**CsvCodec, XlsCodec, XlsxCodec**

```
//If you use CsvCodec, XlsCodec or XlsxCodec as Decoder you have to specify the input file name.
$csvDecoder = new CsvCodec("test_file.csv");
$xlsDecoder = new XlsCodec("test_file.xls");
$xlsxDecoder = new XlsxCodec("test_file.xlsx");

//If you use CsvCodec, XlsCodec or XlsxCodec as Coder you have two options.

//First option: You specify the file name, thus the coder will write out the table in that file.
Converter::convert(new CsvCodec("test_file.csv"), new SimpleAssociationRule(), new XlsxCodec("new_test_file.xlsx"));

//Second option: If you don't set the filename parameter, the coder will return with the file as a string.
$xls = Converter::convert(new CsvCodec("test_file.csv"), new SimpleAssociationRule(), new XlsxCodec());
```

**MysqliCodec**

```
//If you use MysqliCodec as Coder, you have to set the mysqli connection and the name of the table
$db = new mysqli('localhost', 'user', 'pass', 'demo');
if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}
$mysqliCoder = new MysqliCodec($db,"table_name");

//If you use MysqliCodec as Decoder, you have to more options. Firstly, you can use as same as in Coder. It will
//select the whole table with all column.
$mysqliDecoder = new MysqliCodec($db,"table_name");

//Another option is that you write an arbitrary sql query. In this case, you can leave the table name empty.
$mysqliDecoder = new MysqliCodec($db,"","SELECT * FROM table_name WHERE col1 > 5 OR col2 = 44");
$mysqliDecoder2 = new MysqliCodec($db,"","SELECT * FROM table_name JOIN table_name2 ON (table_name.id = table_name2.id)");
```

\##AssociationRule

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~198 days

Recently: every ~338 days

Total

8

Last Release

1995d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c901ad91a0e6aab434876f5c9c0d5e82e0a30973a55c8a4ba5e31382e2c8fc4b?d=identicon)[nagyatka](/maintainers/nagyatka)

---

Top Contributors

[![nagyatka](https://avatars.githubusercontent.com/u/3961400?v=4)](https://github.com/nagyatka "nagyatka (16 commits)")

---

Tags

arraymysqlxlsxlsxcsvconverter

### Embed Badge

![Health badge](/badges/nagyatka-tableconverter/health.svg)

```
[![Health](https://phpackages.com/badges/nagyatka-tableconverter/health.svg)](https://phpackages.com/packages/nagyatka-tableconverter)
```

###  Alternatives

[kartik-v/yii2-export

A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)

1623.1M35](/packages/kartik-v-yii2-export)[jianyan74/php-excel

php excel 导入导出

5842.2k4](/packages/jianyan74-php-excel)[jgrygierek/batch-entity-import-bundle

Importing entities with preview and edit features for Symfony.

101.1M1](/packages/jgrygierek-batch-entity-import-bundle)[nilgems/laravel-textract

A Laravel package to extract text from files like DOC, XL, Image, Pdf and more. I've developed this package by inspiring "npm textract".

195.2k](/packages/nilgems-laravel-textract)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
