Reporting Tools In PHP

This tutorials intend to show you the available tools that can be use for creating reports in PHP. It does not matter if your report consist of simple to complex tabular format report, charts or graphs. I will show you the easiest way in creating graphs and charts reporting and export it to word. I can show you just how simple it is to export tabular format reports that you have created to words and excel.

Exporting tabular format report to word and excel.

1. Just imagine you have prepared a web report in php. Then suddenly your bos wants to print the report and the report printed is not what your bos expected. It comes out sometimes out of margin and at the end of the page the table look like has been cut out because the table is too long. Then your bos wants you to export the table in the report to Microsoft Word. Because he wants to edit something and wants to get the report stored digitally in his laptop for his next meeting. Then your bos come up to you saying that he wants the table to be in the excel format also.

Don’t worry. I have a simple way on dealing with the issues. My approach is not the best one. But it is the simplest way to tackle this issue.

1. Imagine that you have already prepare a web tabular format report in php and wanted to export it to word and excel. My approach is to make a copy of the code that you have done. For instance you created the report in report1.php file. Just create an identical report just like the report1.php and named it as report1convert.php.

2. Next step is we have to edit the report1convert.php so that the page can be converted into Microsoft Word or Excel format. In order to achieve this, you have to take away all of the html tags and all the xhtml headers. Or if you include the header from someplace else, just comment the codes. The objectives is we do not want the html headers, html tags and also the banners, footers. Also take away all the body tags, title tags and head tags. But you can leave the div tags and the form tags.If you miss one you cannot convert the page to Ms Word and Excel.

3. After you have finish removing all the html tags, add this line of code so that the page can accept an argument. You can use what ever name that u like. I use ‘file’ and save it in $file variable. Add the code to the top of the page.

$file = $_REQUEST[‘file’];

This is because we will send an argument to the report1convert.php so that it will determine wether we want the page to be in Ms Word format or an Excel format.

4. After this all you have to do is add the code below. Put the code above your table report that you created.

if($file == ‘excel’)
 header(“Content-Type: application/”);
 header(“Content-Disposition: attachment; filename=\”laporan10.xls\””);
 header(“Pragma: no-cache”);
 header(“Expires: 0”);

if($file == ‘word’)
 header(“Content-Disposition: attachment; filename=\”laporan10.doc\””);
 header(“Content-Type: application/”);
 header(“Pragma: no-cache”);
 header(“Expires: 0”);

Then your page is ready to be exported to Ms Word or Excel format.

5. The last thing that you should do is put a Ms Word and Excel icons or links to report1convert.php from report1.php. The link should be something like this:

<a target=”_self” href=”report1convert.php?file=word” mce_href=”report1convert.php?file=word” title=”Export to MS WORD”>Export to Microsoft Word</a>

<a target=”_self” href=”report1convert.php?file=excel” mce_href=”report1convert.php?file=excel” title=”Export to MS EXCEL”>Export to Microsoft Excel</a>

Try it….


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed

%d bloggers like this: