GithubHelp home page GithubHelp logo

phpreport's Introduction

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

It's based on PHPExcel, so download it and extract next to PHPReport.php file. To start using it, simply include PHPReport.php in your script and follow the documentation.

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:

$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();

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.

$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();

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

phpreport's People

Contributors

vernes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.