PHPackages                             agoussec/phpdbtabletoexcel - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. agoussec/phpdbtabletoexcel

ActiveLibrary[File &amp; Storage](/categories/file-storage)

agoussec/phpdbtabletoexcel
==========================

Create Excel sheet directly from database table rows

1.12(4y ago)410GPL-3.0-onlyPHP

Since Mar 27Pushed 4y ago2 watchersCompare

[ Source](https://github.com/agoussec/PHPDBTabletoExcel)[ Packagist](https://packagist.org/packages/agoussec/phpdbtabletoexcel)[ RSS](/packages/agoussec-phpdbtabletoexcel/feed)WikiDiscussions main Synced today

READMEChangelog (4)DependenciesVersions (5)Used By (0)

PHPDBTabletoExcel
=================

[](#phpdbtabletoexcel)

Create Excel sheet directly from database table's rows

Getting Started
---------------

[](#getting-started)

PHPDBTabletoExcel is a very simple and easy to use PHP package for generating Excel file from database table SQL query.

It can connect to a database using PDO and executes a given SQL database table query.

The class executes the query and then outputs the results to a file in HTML table based format that is served for download and can be read and imported correctly by Microsoft Excel.

### Prerequisites

[](#prerequisites)

No requirements for now!

### Installing

[](#installing)

Install using composer

```
composer require agoussec/phpdbtabletoexcel

```

Create Object of Class and start using it directly by adding in your project files if autoload is enabled, if not then include class file in your project.

```
use agoussec\class\Export;
$export = new Export();

```

Usage Example
-------------

[](#usage-example)

#### *Way 1 for initializing database connection*

[](#way-1-for-initializing-database-connection)

You can pass database credentials while creating object of class.

```
$exportObject = new Export('localhost', 'dbuser', 'password', 'database');

```

#### *Way 2 for initializing database connection*

[](#way-2-for-initializing-database-connection)

Create PDO connection and pass PDO object to `setConnection()` method

```
$Conn = new PDO('mysql:host=localhost;dbname=dbname', 'dbuser', "dbpassword");
$export->setConnection($Conn);

```

#### Set SQL Query

[](#set-sql-query)

```
$sql = "SELECT
           table2.column1 as `Column 1`,
           table3.column2 as `Column 2`,
           table1.column3 as `Column 3`,
        FROM `table1`
           left JOIN table2 ON table2.id = table1.table2id
           left JOIN table3 ON table3.id = table1.table3id
        WHERE table1.status = 1";

 $export->setQuery($sql);

```

#### Set table rows (optional)

[](#set-table-rows-optional)

```
$export->setData($PDOFETCHEDARRAY);

```

#### Exported File Name (optional)

[](#exported-file-name-optional)

```
$export->setFilename('setFilename');

```

#### Header row in exported excel sheet (optional)

[](#header-row-in-exported-excel-sheet-optional)

```
$export->setHeaderRow(true);

```

#### Time Stamp (optional)

[](#time-stamp-optional)

```
$export->setTimestamp(true);

```

#### And at last get the Excel file -

[](#and-at-last-get-the-excel-file--)

```
$export->getFile();

```

Authors
-------

[](#authors)

- **Shamsh Pravez** - *Initial work* - [agoussec](https://github.com/agoussec)

License
-------

[](#license)

This project is licensed under the GNU General Public License v3.0 - see the LICENCE file for details

###  Health Score

25

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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 ~0 days

Total

4

Last Release

1820d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/44767182af477decbc52e69a70c631585d6fe1772cb02e551e55bd64a5eb242a?d=identicon)[agoussec](/maintainers/agoussec)

---

Top Contributors

[![agoussec](https://avatars.githubusercontent.com/u/16516713?v=4)](https://github.com/agoussec "agoussec (13 commits)")

### Embed Badge

![Health badge](/badges/agoussec-phpdbtabletoexcel/health.svg)

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

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.2M116](/packages/knplabs-gaufrette)[aws/aws-sdk-php-laravel

A simple Laravel 6/7/8/9/10/11/12 service provider for including the AWS SDK for PHP.

1.7k34.8M69](/packages/aws-aws-sdk-php-laravel)[vich/uploader-bundle

Ease file uploads attached to entities

1.9k25.4M107](/packages/vich-uploader-bundle)[spatie/simple-excel

Read and write simple Excel and CSV files

1.3k9.4M39](/packages/spatie-simple-excel)[knplabs/knp-gaufrette-bundle

Allows to easily use the Gaufrette library in a Symfony project

73628.2M84](/packages/knplabs-knp-gaufrette-bundle)[google/cloud-storage

Cloud Storage Client for PHP

34388.1M95](/packages/google-cloud-storage)

PHPackages © 2026

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