Add a page?

Topics: User Forum
Dec 26, 2008 at 5:00 PM
I've tried the function "addSheet()" in several ways and was never able to make it work out. I found a way to make it work when you copy the first sheet on this discussion board (pasted below), but I suppose then I'd have to clear everything. I try to test out any way I can think of that may work before asking for help...but this one seems easy but I just don't have the resources to make any headway with it.

// copy sheet
$page2 = $objPHPExcel->getActiveSheet()->copy();
$page2->setTitle("TEST");
$page2->setCellValue('B1', 'TEST');
$objPHPExcel->addSheet($page2);

This is probably a walk in the park for most of you...but I appreciate it :P
Developer
Dec 26, 2008 at 8:53 PM
Easiest way to add sheet:

$objWorksheet = $objPHPExcel->createSheet();
$objWorksheet->setTitle('zebra');

Under the hood, createSheet() uses addSheet() like this, which also works:

$objWorksheet = new PHPExcel_Worksheet($objPHPExcel);
$objPHPExcel->addSheet($objWorksheet);
$objWorksheet->setTitle('zebra');

But again, createSheet() is probably easier, so just use that.