setActiveSheet(1) crashes

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

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

 $objPHPExcel->setActiveSheetIndex(1); crashes ?

Regards

Deepak Bhatia
Coordinator
Feb 17, 2009 at 4: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 3:03 AM
Hi,

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
    $objPHPExcel->setActiveSheetIndex(0);

   $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
   $objWriter->save('var/tmp/test.xls');
========================================================
Developer
Feb 18, 2009 at 3:15 AM
Easiest way is using createSheet()
http://www.codeplex.com/PHPExcel/Thread/View.aspx?ThreadId=43036
Feb 18, 2009 at 3:53 AM
Dear Mr. Koyama,

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

Regards

Deepak Bhatia