Download the PHP package hstanleycrow/easyphpreports without Composer
On this page you can find all versions of the php package hstanleycrow/easyphpreports. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hstanleycrow/easyphpreports
More information about hstanleycrow/easyphpreports
Files in hstanleycrow/easyphpreports
Package easyphpreports
Short Description PHP library to generate Excel, CSV and PDF reports from tabular data definitions, built on PhpSpreadsheet and mPDF.
License MIT
Homepage https://github.com/hstanleycrow/EasyPHPReports
Informations about the package easyphpreports
EasyPHPReports
PHP library to generate Excel, CSV and PDF reports (plus ready-to-embed HTML) from plain tabular data. It is a thin, opinionated layer on top of PhpSpreadsheet and mPDF: you describe the columns once and hand over an array of rows, and the library takes care of headers, number/date formatting, column sizing and summary totals.
- Spanish version: README.es.md
- AI consumption spec: AI_USAGE.es.md
Features
- One definition, four outputs: on-screen HTML table,
.xlsx,.csv,.pdf. - Per-column formats: text, number, decimal, money, date, datetime.
- Optional summary row per column (
SUMfor numeric,COUNTIFfor text/date). - Automatic date conversion, column auto-sizing and word-wrap for long values.
- No database required — it works with any array of rows, wherever they come from.
Requirements
- PHP
^8.2 ext-zip(required by PhpSpreadsheet to write.xlsx)ext-gdandext-mbstring(required by mPDF to write.pdf)
Installation
Quick start
The library only needs two things: a columns definition and an array of rows. Each row is an associative array whose values are read in order — the keys are up to you, but the value order must match the columns definition.
The sample data above is hardcoded for illustration only. In a real application the rows would come from a database, an API, or any other source. The library does not depend on any specific data source.
Generating downloadable files
For EXCEL, CSV and PDF you must pass a file path (without extension — it is added
automatically). Make sure the target directory exists and is writable.
Swap PHPReport::EXCEL for PHPReport::CSV or PHPReport::PDF to get the other formats —
everything else stays the same.
Column definition
Each entry in the columns array is an associative array with three keys:
| Key | Type | Description |
|---|---|---|
header |
string |
Column title shown in the first row. |
format |
string |
One of the CellFormat constants (see below). |
calculate |
bool |
When true, adds a summary row at the bottom for that column. |
CellFormat constants
| Constant | Cell format | Summary (calculate: true) |
Expected input value |
|---|---|---|---|
CellFormat::TEXT |
General text | COUNTIF (non-empty count) |
any string |
CellFormat::NUMBER |
Integer number | SUM |
numeric |
CellFormat::DECIMAL |
Decimal, thousands | SUM |
numeric |
CellFormat::MONEY |
USD currency ($) |
SUM |
numeric |
CellFormat::DATE |
DD/MM/YYYY |
COUNTIF |
string in Y-m-d format |
CellFormat::DATETIME |
DD/MM/YYYY HH:MM:SS |
COUNTIF |
string in Y-m-d H:i:s format |
An invalid DATE/DATETIME value throws InvalidArgumentException.
Public API
| Member | Signature | Description |
|---|---|---|
PHPReport::initialize() |
static initialize(): void |
Registers the four built-in report types. Call once before generating. |
new PHPReport(...) |
__construct(string $type, array $columns, array $rows, ?string $filepath = null) |
Creates a report of the given type. |
PHPReport::generate() |
generate(): string |
Builds the report. Returns the HTML table (SCREEN) or the saved file path. |
PHPReport::isDownloadable() |
isDownloadable(): bool |
false for SCREEN, true for EXCEL/CSV/PDF. |
PHPReport::registerType() |
static registerType(string $type, string $className): void |
Registers a custom report type (advanced/extension use). |
Report types
| Constant | Output | filepath |
generate() returns |
isDownloadable() |
|---|---|---|---|---|
PHPReport::SCREEN |
HTML <table> |
ignored | HTML string | false |
PHPReport::EXCEL |
.xlsx file |
required | file path | true |
PHPReport::CSV |
.csv file |
required | file path | true |
PHPReport::PDF |
.pdf file |
required | file path | true |
Notes and limitations
- Value order matters. Each row is consumed positionally; the Nth value maps to the Nth column regardless of its array key. Keep the same order in every row.
SCREENreturns an HTML<table>styled with Bootstrap-friendly classes (table table-bordered table-responsive); it is meant to be embedded in your own page.EXCEL/CSV/PDFrequire a writable target directory; the extension is appended for you.- The
MONEYformat is fixed to USD ($). - Summary rows use spreadsheet formulas; spreadsheet apps (Excel, LibreOffice) recompute them on open.
- The value returned by
generate()forEXCEL/CSV/PDFis a filesystem path, NOT a URL — do not concatenate it raw into anhref. If you build a download link,rawurlencode()the filename segment (spaces/accents break the URL otherwise); prefer ASCII-safe filenames when the name comes from business data, and sanitize it before passing it asfilepath. Prefer serving the file through a controlled endpoint withContent-Disposition: attachment; filename="..."instead of exposing the export directory.
License
MIT © Harold Rivas (Harold Crow)