setActiveSheet(1) crashes

Topics: Developer Forum, User Forum
Feb 17, 2009 at 10:30 AM

Is it possible to work with multiple sheets in the Excel document ?

 $objPHPExcel->setActiveSheetIndex(1); crashes ?


Deepak Bhatia
Feb 17, 2009 at 5:19 PM
It is, but if you're using $objPHPExcel->setActiveSheetIndex(1) then the sheet you're setting to active must exist. The default sheet is sheet number 0 if you've created a PHPExcel wokbook using new. If you've read a workbook from file, then it may have a varying number of sheets, but they'll still be indexed with 0 as the first.
Feb 18, 2009 at 4:03 AM

Thanks for your reply.

I am currently interested in creating the Excel documents as given below. How do I get to work with Sheet 1 ?

// Create new PHPExcel object
    $objPHPExcel = new sfPhpExcel();

// Rename sheet
    $objPHPExcel->getActiveSheet()->setTitle('Project Report');

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet

   $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
Feb 18, 2009 at 4:15 AM
Easiest way is using createSheet()
Feb 18, 2009 at 4:53 AM
Dear Mr. Koyama,

Thanks for your help. The createSheet() is the solution.


Deepak Bhatia