PHPExcel_Reader_Excel2007 returns -1 on getWidth()

Topics: Developer Forum, User Forum
Oct 6, 2011 at 2:44 PM

Hi there,

I like PHPExcel and it's so much better than the old abandoned Spreadsheet_Excel_Writer, but in some cases it seems to create random results on some function calls:

My application uses an Excel template (Excel 2007 format) to define its spreadsheet layouts (and I wonder why it has to be so complicated to apply styles), beginning with the column width and then adding styles to cells one after the other. All of the sudden, I keep getting a -1 result when retrieving the column width:

    $excelReader= new PHPExcel_Reader_Excel2007();
    $this->reader= $excelReader->load(dirname(__FILE__)."/report.xlsx");

    $sheetReader= $this->reader->getActiveSheet();

    // set column width
    $letterStart= ord("A");
    $letterEnd= ord("V");
    for (;$letterStart <= $letterEnd;$letterStart++) {
      // getWidth() keeps on returning -1

Is this a known problem?

Thanks for any help in advance!

Best regards, Sascha

Nov 10, 2011 at 11:21 AM


I have the same problem. I create a new file and


always return -1.

Is there another way to get the height of a row?

Greets, Isa

Nov 10, 2011 at 11:30 AM

Hi Isa,

could you post some more of your code? I found a solution to my problem, the solution was not to use a reference to the active spreadsheet but to retrieve the column dimensions through the reader object directly:

$excelReader= new PHPExcel_Reader_Excel2007();
$this->reader= $excelReader->load(dirname(__FILE__)."/report.xlsx");

$height= $this->reader->getActiveSheet()->getRowDimension(1)->getRowHeight();

Hope that helps!

Regards, Sascha