Generating Excel Spreadsheets with PHP and PEAR

Spreadsheet_Excel_Writer  is the Package for generating Excel spreadsheets (.xls)
Download the package and put the Spreadsheet folder inside PEAR.
The php code to export must be as below sample  code
<?php
require_once ‘pear/Writer.php’;
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();
// Creating a worksheet
$worksheet =& $workbook->addWorksheet(‘Test Excel Export’);
$cost_format =& $workbook->addFormat();
$cost_format->setNumFormat(“0.00″);
$format_bold =& $workbook->addFormat();
$format_bold->setBold();
$format_title =& $workbook->addFormat();
$format_title->setBold();
$format_title->setColor(‘yellow’);
$format_title->setPattern(1);
$format_title->setFgColor(‘blue’);
// Table headers
$worksheet->write(0, 0, ‘Currency’, $format_bold);
$worksheet->write(0, 1, ‘# Transactions’, $format_bold);
$worksheet->write(0, 2, ‘Total Amount’, $format_bold);
$worksheet->write(0, 4, ‘Cost’, $format_bold);
// create output
$worksheet->write(1, 0, ‘USD’);
$worksheet->write(1, 1, ‘3′);
$worksheet->write(1, 2, 33);
$worksheet->write(1, 3, 99.99);
$worksheet->writeNumber(1, 4, 99.99, $cost_format);
$worksheet->write(2, 0, ‘USD’);
$worksheet->write(2, 1, ‘3′);
$worksheet->write(2, 2, 33);
$worksheet->write(2, 3, 99.99);
$worksheet->writeNumber(2, 4, 99.99, $cost_format);
// sending HTTP headers
$workbook->send(‘transactions.xls’);
$workbook->close();
?>
it will export the xls with 2 results

Comments

Popular posts from this blog

111 Most Useful Websites on the Internet

How to call php functions inside smarty template directly

How to improve PHP web performance