PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » File Formats » Spreadsheet_Excel_Writer » Bug #6067

Warnings are thrown if using a cell format

Details

Submitted2005-11-25 10:46 UTC
Fromshadowlord at hltools dot com
StatusDuplicate
PackageSpreadsheet_Excel_Writer
PHP Version5.1.0
OSAny
Roadmaps(Not assigned)

Comments

[2005-11-25 10:46 UTC] shadowlord at hltools dot com

Description:
------------
PEAR version: 1.4.5
Spreadsheet_Excel_Writer version 0.9.0
Standard PHP 5.1.0 release (Windows binaries, zip file)
php.ini tuned for maximum error reporting.

The problem:
A warning message is generated when writing to a cell with a format variable using the write() or writeBlank() functions. This is because the variable is a object, but internally it is compared against an integer (0) to see if a format was passed. This should be replaced with the is_object() function (or similar).
The warnings corrupt the outputted Excel file

Note:
I have not extensivly tested for all occurences of this bug. There could be (and probably are) more instances of it.

Test script:
---------------
<?PHP
// Set up
error_reporting(E_ALL); // All errors except strict
require_once("Spreadsheet/Excel/Writer.php"); // Load excel file creator
$workbook = new Spreadsheet_Excel_Writer();
$workbook->send("Errors demonstration.xls");
$worksheet =& $workbook->addWorksheet('Demo worksheet');

// Create demonstration format
$format =& $workbook->addFormat();
$format->setBold();

// Error on writing cell
$worksheet->write(0, 0, "Test", $format);

// Error on writing blank cell
$worksheet->writeBlank(0, 1, $format);

// Output file
$workbook->close();
?>

Expected result:
----------------
An Excel file containing:
Cell A1 - The word 'Test' in bold
Cell B1 - Blank and set to bold

Actual result:
--------------
An Excel file containing:

Notice: Object of class Spreadsheet_Excel_Writer_Format could not be converted to int in C:\PHP\PEAR\Spreadsheet\Excel\Writer\Worksheet.php on line 1233

Notice: Object of class Spreadsheet_Excel_Writer_Format could not be converted to int in C:\PHP\PEAR\Spreadsheet\Excel\Writer\Worksheet.php on line 1686

Notice: Object of class Spreadsheet_Excel_Writer_Format could not be converted to int in C:\PHP\PEAR\Spreadsheet\Excel\Writer\Worksheet.php on line 1233
<BINARY CODE - presumably the completed (but now corrupt) Excel file>

[2006-03-09 13:19 UTC] andrea dot busia at axis-sv dot it

with the following small changes i'm not receiving noticies.

Andrea Busia

diff:
-----------------------
(<)Worksheet_old.php (112151 byte)
(>)Worksheet.php (112180 byte)

1233c1233
< if ($format != 0) {
---
> if (is_object($format)) {
1686c1686
< if ($format == 0) {
---
> if (is_numeric($format) && $format == 0) {