Read - Write - Read Inconsistency

Topics: User Forum
Oct 31, 2009 at 2:48 AM

PHP 5.2.8, PHPExcel 1.7.0, Vista


I load foo.xls, then save it to bar.xls.  Then, I test the highest row and column.  They are not identical.

foo.xls is an extremely simple sample file, no formulas or formatting, with columns A-Z counting from 1 to 50.  Text only.

Here is the PHP code and output:

require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/IOFactory.php';

//Load foo.xls
$file = "foo.xls";
$objPHPExcel    = new PHPExcel();
$objReader      = PHPExcel_IOFactory::createReader("Excel5");
$objPHPExcel    = $objReader->load($file);

//Echo dimensions
  $objPHPExcel->getActiveSheet()->getHighestColumn()." ".
  $objPHPExcel->getActiveSheet()->getHighestRow();    //Returns: Z 53

//Write foo.xls to bar.xls
$objWriter      = PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel5");

//Load bar.xls
$objPHPExcel    = $objReader->load("../spreadsheets/bar.xls");

//Echo dimensions
echo "<br />".
  $objPHPExcel->getActiveSheet()->getHighestColumn()." ".
  $objPHPExcel->getActiveSheet()->getHighestRow();    //Returns: IU 1

The dimensions of foo.xls  are Z, 53.  The dimensions of bar.xls are IU, 1.  The filesize also jumped from 21k to 39k.

What's going on?

Oct 31, 2009 at 4:11 AM

This has something to do with the way PHPExcel works with columns. Changes are needed to solve this bug and some other similar bugs having to do with columns.

I have now posted this in the issue tracker so you can track when the problem is fixed. Not sure right now when this can be fixed. It is a bit harder to solve than it may seem.

Oct 31, 2009 at 4:42 AM

OK. BTW, I also tested it with a smaller worksheet, only fifteen cells, and the returns were "C 5" and "IU 1".  The consistent return on the re-read may be a clue, hope it helps. 


Oct 31, 2009 at 11:16 AM

IU is definitely an interesting column value A-IV is the range of columns in Excel 5, (1-256). Adjusted to 0-255, that would give IU.