adding worksheets

Dec 21, 2010 at 11:04 AM

This problem has turned up at the beginning of trying to use this.

This just the base - total groups = 61

  $x = 1;   
  foreach ($groups as $ID_Group => $Name_Group)
      if($Name_Group != 'Gesamt') {
        $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Kto.:'.$groupaccountnrs[$ID_Group]);

And this throws the following error
11:49:05 Create new PHPExcel object
PHP Fatal error:  Uncaught exception 'Exception' with message 'Active sheet index is out of bounds.' in /var/www/html/dailyreport/classes/PHPExcel.php:371
Stack trace:
#0 /var/www/html/dailyreport/new_index.php(1912): PHPExcel->setActiveSheetIndex(9)
#1 {main}
  thrown in /var/www/html/dailyreport/classes/PHPExcel.php on line 371


Any ideas why ?

Dec 21, 2010 at 11:22 PM

Sheets are indexed from 0, not from 1... so the first sheet you add using createSheet() is index 0, but your setActiveSheetIndex($i) is trying to set the active index to 1.

Dec 22, 2010 at 8:36 AM

I thought i had a sheet already, this is the two lines above the script


$objPHPExcel = new PHPExcel();
  $x = 1;  


so theoretically i am trying to create sheet 1++ as i already have a 0 or have i missed something ?

Dec 22, 2010 at 10:20 AM

You might change your code to:


because createSheet() with an index value argument will automatically set the newly created sheet to be the active sheet.


Or set the active sheet to $x rather than $i



Dec 23, 2010 at 9:16 AM

that does this trick !