PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I tried using PEAR's Spreadsheet_Excel_Writer to generate Excel XLS file. Initial results were good until I turned on E_STRICT and up came the flashing lights. (see below) . I am using PHP 5.2. Am I going something wrong? Can I trust that this code will continue to work in future releases? Has this package been updated/replaced?
<?php
error_reporting(E_ALL | E_WARNING | E_STRICT );
ini_set('display_errors', TRUE);
@unlink('binary.xls');
// Include PEAR::Spreadsheet_Excel_Writer
require_once "Spreadsheet/Excel/Writer.php";
// Create an instance, passing the filename to create
$xls =& new Spreadsheet_Excel_Writer('binary.xls');
// Add a worksheet to the file, returning an object to add data to
$sheet =& $xls->addWorksheet('Binary Count');
$csvLine = array("Ticket Number",
"Sys.Serv",
"Period",
"WO Rcv'd",
"Message",);
$excelColCount=0;
foreach ($csvLine as $item)
{
$sheet->write(0,$excelColCount++,$item);
}
// Write some numbers
for ( $i=0;$i<11;$i++ ) {
// Use PHP's decbin() function to convert integer to binary
$sheet->write($i,0,decbin($i));
}
// Finish the spreadsheet
$xls->close();
?>
Strict Standards: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\PEAR.php on line 569
Strict Standards: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\PEAR.php on line 572
Strict Standards: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Spreadsheet\Excel\Writer\Workbook.php on line 186
Strict Standards: Assigning the return value of new by reference is deprecated in C:\xampp\php\pear\Spreadsheet\Excel\Writer\Workbook.php on line 195
Strict Standards: Non-static method OLE::Asc2Ucs() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\Spreadsheet\Excel\Writer\Workbook.php on line 586
Strict Standards: is_a(): Deprecated. Please use the instanceof operator in C:\xampp\php\pear\PEAR.php on line 281
Strict Standards: Non-static method OLE::Asc2Ucs() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\OLE\PPS\Root.php on line 52
Strict Standards: Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in C:\xampp\php\pear\OLE\PPS.php on line 186
Thanks for your input but even with changes suggested, there are many deprecation errors coming from PEAR code, plus company does not have PEAR installed. I found a bare bones class at http://www.phpclasses.org which will do for now.
If you are using Windows server try Excel COM objects. If it's not the case try using CSV with content-type: Excel headers.
I used Spreadsheet_Excel_Writer for a while, but there were some issues (Excel, IMHO) so I decide not to use it.
There are 10 types of people in this world, those who understand binary and those who don't
itp wrote:Thanks for your input but even with changes suggested, there are many deprecation errors coming from PEAR code, plus company does not have PEAR installed. I found a bare bones class at http://www.phpclasses.org which will do for now.
If you're looking for an alternative to the PEAR Spreadsheet_Excel_Writer, try taking a look at alternatives that are still supported such as PHPExcel