This article describes the PHP spreadsheet_excel_writer and how to generate Excel files.
First step, install Spreadsheet_excel_writer because this package uses OLE packages, you may need to install it
Perform the following command to perform the update: Update pear.php.net ole-0.5 spreadsheet_excel_writer-0.9.1
Looking at an instance, Myfile.xls is the filename (including the path), and the workbook contains a list of student lists
<?php
Require_once ' spreadsheet/excel/writer.php ';
Creating workbook
$workbook = new Spreadsheet_excel_writer (' Myfile.xls ');
adding worksheet
$worksheet =& $workbook->addworksheet (' Students ');
Data input
$worksheet->write (0, 0, ' name ');
$worksheet->write (0, 1, ' grade ');
$worksheet->write (1, 0, ' Ivancho ');
$worksheet->write (1, 1, 7);
$worksheet->write (2, 0, ' Mariika ');
$worksheet->write (2, 1, 7);
$worksheet->write (3, 0, ' Stoyancho ');
$worksheet->write (3, 1, 8);
Saving file
$workbook->close ();
?>
Here is a section to export data to the user to save it.
<?php
Require_once ' spreadsheet/excel/writer.php ';
Creating workbook
$workbook = new Spreadsheet_excel_writer ();
Sending headers to browser
$workbook->send (' Students.xls ');
adding worksheet
$worksheet =& $workbook->addworksheet (' Students ');
Data input
$worksheet->write (0, 0, ' name ');
$worksheet->write (0, 1, ' grade ');
$worksheet->write (1, 0, ' Ivancho ');
$worksheet->write (1, 1, 7);
$worksheet->write (2, 0, ' Mariika ');
$worksheet->write (2, 1, 7);
$worksheet->write (3, 0, ' Stoyancho ');
$worksheet->write (3, 1, 8);
Sending the file
$workbook->close ();