PHP Classes

PHP Report: Generate Excel, HTML, PDF reports from data arrays

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum (14)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (4 months ago) RSS 2.0 feedStarStarStarStar 70%Total: 7,717 This week: 1All time: 230 This week: 61Up
Version License PHP version Categories
php-report 1.14GNU Lesser Genera...5.2PHP 5, Files and Folders
Description 

Author

This class can generate reports in Excel, HTML and PDF formats from arrays of data.

It takes arrays of data that define the contents and format of cells of a spreadsheet and it generates an spreadsheet file using the PHPExcel package in several formats like Excel, HTML and PDF.

The class allows defining the content and format of header and footer cells, alignment and width for different groups of cells, define groups of cells, etc..

Picture of verni
Name: verni <contact>
Classes: 1 package by
Country: Bosnia and Herzegovina Bosnia and Herzegovina
Age: 39
All time rank: 3452 in Bosnia and Herzegovina Bosnia and Herzegovina
Week rank: 72 Up2 in Bosnia and Herzegovina Bosnia and Herzegovina Equal

Example

<?php

include '../PHPReport.php';

$R=new PHPReport();
$R->load(array(
           
'id'=>'product',
           
'data'=>array(
                        array(
'Some product',23.99,12),
                        array(
'Other product',5.25,2.25),
                        array(
'Third product',0.20,3.5)
                )
            )
        );

echo
$R->render();
exit();


Details

PHPReport

PHPReport is a class for building and exporting reports from PHP. It's based on powerful PHPExcel library and includes exporting to popular formats such are HTML, Excel or PDF.

Features

  • Simple for using
  • Many ways to customize your input data
  • Build reports based on predefined templates
  • Export to HTML, Excel (xlsx and xls) and PDF

Installation

Install composer, and run composer update to install the required PHPExcel dependencies

Usage and examples

Basicly, there are two way to build a report.

Building it "from scratch"

PHPReport does all the work, your just provide it with your data, like this: <pre> $R=new PHPReport(); $R->load(array(

        'id'=>'product',
        'data'=>array(
                    array('Some product',23.99),
                    array('Other product',5.25),
                    array('Third product',0.20)
            )
        )
    );

$R->render(); </pre>

It's great for exporting tabular data. Input data can be further formatted, grouped and customized. See the wiki.

Building it from template

Template is usually some excel file, already formatted and with placeholders for data. There are two types of placeholders: static and dynamic. Static placeholders are, for example, some data like date, city or customer name. Dynamic placeholders are, for example, list of products with variable number of rows.

<pre> $R=new PHPReport(array('template'=>'invoice_template.xls')); $R->load(array(

	array(
			'id'=>'invoice',
			'data'=>array(
				'date'=>date('Y-m-d'),
				'number'=>'000312',
				'customer_id'=>'512',
				'expiration_date'=>date('Y-m-d',strtotime('+30day')),
				'name'=>'John Doe',
				'company'=>'Example, inc',
				'address'=>'Some address',
				'city'=>'Gotham City',
				'zip'=>'0123',
				'phone'=>'+123456'
			),
			'format'=>array(
				'date'=>array('datetime'=>'d/m/Y'),
				'expiration_date'=>array('datetime'=>'d/m/Y')
			)
		),
	array(
			'id'=>'product',
			'data'=>array(
				array('description'=>'Some product','price'=>23.99,'total'=>23.99),
				array('description'=>'Other product','price'=>5.25,'total'=>2.25)
			),
			'repeat'=>true,
			'format'=>array(
				'price'=>array('number'=>array('prefix'=>'$','decimals'=>2)),
				'total'=>array('number'=>array('prefix'=>'$','decimals'=>2))
			)
		)
	)
);

$R->render(); </pre>

These reports are great for complex exports like invoices. See the wiki for more examples.


Screenshots  
  • phpreport_example.png
  Files folder image Files  
File Role Description
Files folder imageexamples (10 files)
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file Advanced_examples.txt Doc. Some examples with templates
Accessible without login Plain text file Examples.txt Doc. Some examples
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file PHPReport.php Class Class source

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file example_1.php Example Example script
  Accessible without login Plain text file example_10.php Example Example script
  Accessible without login Plain text file example_2.php Example Example script
  Accessible without login Plain text file example_3.php Example Example script
  Accessible without login Plain text file example_4.php Example Example script
  Accessible without login Plain text file example_5.php Example Example script
  Accessible without login Plain text file example_6.php Example Example script
  Accessible without login Plain text file example_7.php Example Example script
  Accessible without login Plain text file example_8.php Example Example script
  Accessible without login Plain text file example_9.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 81%
Total:7,717
This week:1
All time:230
This week:61Up
User Ratings User Comments (3)
 All time
Utility:92%StarStarStarStarStar
Consistency:87%StarStarStarStarStar
Documentation:70%StarStarStarStar
Examples:82%StarStarStarStarStar
Tests:-
Videos:-
Overall:70%StarStarStarStar
Rank:264
 
Obviously this package is very much helpful.
9 years ago (ashish)
75%StarStarStarStar
once I stopped using PHPExcel reason there is a problem under...
11 years ago (Abdul Muhaimin)
80%StarStarStarStarStar
Need a revision
12 years ago (Andres Vanegas)
67%StarStarStarStar