crash if > 99999 rows?

Topics: Developer Forum, User Forum
Feb 9, 2011 at 9:47 AM

Hi,

I've run into problems craeting an excelsheet with > 100K rows. It seems phpExcel checks if a cell coordinate is valid in the following function:

	public static function coordinateFromString($pCoordinateString = 'A1')
	{
		if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,5})$/", $pCoordinateString, $matches)) {
			return array($matches[1],$matches[2]);
		} elseif ((strpos($pCoordinateString,':') !== false) || (strpos($pCoordinateString,',') !== false)) {
			throw new Exception('Cell coordinate string can not be a range of cells.');
		} elseif ($pCoordinateString == '') {
			throw new Exception('Cell coordinate can not be zero-length string.');
		} else {
			throw new Exception('Invalid cell coordinate '.$pCoordinateString);
		}
	}

As you can see, the regex checks for a number with up to 5 digits. This causes my script to crash attempting to add the 100000th row:

20110208 17:52:57 Exception caught! exception 'Exception' with message 'Invalid cell coordinate C100000' in /home/report/trunk/MoneyMaker/PHPExcel/Cell.php:501
20110208 17:52:57 Stack trace:
20110208 17:52:57 #0 /home/report/trunk/MoneyMaker/PHPExcel/Worksheet.php(959): PHPExcel_Cell::coordinateFromString('C100000')
20110208 17:52:57 #1 /home/report/trunk/MoneyMaker/PHPExcel/Worksheet.php(880): PHPExcel_Worksheet->getCell('C100000')
20110208 17:52:57 #2 /home/report/trunk/MoneyMaker/Export.class.php(448): PHPExcel_Worksheet->setCellValueByColumnAndRow(2, 100000, '96')
20110208 17:52:57 #3 /home/report/trunk/MoneyMaker/Export.class.php(429): export->addRow(Array, 100000)
20110208 17:52:57 #4 /home/report/trunk/MoneyMaker/Export.class.php(211): export->runQuery('SELECT *??FROM ...', false)

Changing the check seems to fix the problem.

 

Mike

Coordinator
Feb 9, 2011 at 9:57 AM
Edited Feb 9, 2011 at 9:58 AM

Work Item 15029 - already fixed in SVN code on 4th January

Feb 9, 2011 at 10:42 AM

Ah thanks, I did not know that obviously ;) Fix seems the same as my local changes here.

Coordinator
Feb 9, 2011 at 12:41 PM

Yes, all I did to fix this was to change \d{1,5} to \d{1,7} in the regular expression