Creating New Sheets

Nov 29, 2011 at 1:08 PM

I'm having difficulty creating new sheets.  When I create a new sheet and try to change the name I get the following error:

Fatal error: Call to a member function setTitle() on a non-object

My code is as follows:
$workbook->addSheet(); 
$worksheet=$workbook->getActiveSheet(); 
$worksheet->setTitle($sheetName);

I have found a way to get past the error like this:

$sheet=$workbook->getSheet(0);
$workbook->addSheet($sheet);

However, using that method results in Excel telling me the file is damaged.

I'm not sure what I'm doing wrong.

Nov 29, 2011 at 2:08 PM

I do it like this:

$sheetId = 1;
$this->objPHPExcel->createSheet(NULL, $sheetId);
$this->objPHPExcel->setActiveSheetIndex($sheetId);
$this->objPHPExcel->getActiveSheet()->setTitle($index);

Nov 29, 2011 at 2:26 PM
Edited Nov 29, 2011 at 2:27 PM

That worked great! Thanks!