Page 1 of 1

Spreadsheet_Excel_Writer & PHP 5

Posted: Tue Jan 06, 2009 5:55 pm
by itp
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?

Code: Select all

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

Code: Select all

 
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
 
 
 

Re: Spreadsheet_Excel_Writer & PHP 5

Posted: Tue Jan 06, 2009 6:07 pm
by Syntac
Instead of "$xls =& new Something();", use "$xls = new Something();". Assuming that's your code.

I imagine the deprecated code is for backwards compatibility.

Re: Spreadsheet_Excel_Writer & PHP 5

Posted: Wed Jan 07, 2009 3:45 pm
by itp
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.

Just wondering what other people are using

Re: Spreadsheet_Excel_Writer & PHP 5

Posted: Wed Jan 07, 2009 4:08 pm
by VladSun
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.

Re: Spreadsheet_Excel_Writer & PHP 5

Posted: Wed Jan 07, 2009 4:52 pm
by itp
I develop on PC/Windoze but deploy to IBM mid-range box.

Re: Spreadsheet_Excel_Writer & PHP 5

Posted: Thu Jan 08, 2009 3:00 am
by Mark Baker
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