Column index zero-based

Topics: Developer Forum
Jan 30, 2011 at 11:32 AM


I just figured that PHPExcel_Cell::columnIndexFromString returns a zero-based column number, what is correct. Using the returned index in PHPExcel_Cell::stringFromColumnIndex gives a wrong column. Checking the code I saw that the array there is one-based. All documentation says, that columns are zero-based.

Do I understand anything wrong here?

Thanks for any advise.


Jan 30, 2011 at 12:18 PM

This is a historic idiosyncracy, that is retained for backward compatibility. It would be nice to make this consistent, but it would break a lot of existing code were we to do so.

The API docs for the respective methods do indicate the base

  * Column index from string
  * @param string $pString
  * @return int Column index (base 1 !!!)
  * @throws Exception
 public static function columnIndexFromString($pString = 'A')


  * String from columnindex
  * @param int $pColumnIndex Column index (base 0 !!!)
  * @return string
 public static function stringFromColumnIndex($pColumnIndex = 0)

When in doubt, or there is a discrepancy, the API docs should always be treated as the accurate document.

Jan 30, 2011 at 3:46 PM

Thank you for the clarification. You are right, the API description says it correctly.