Delete 1st sheet / create new sheets in a loop

Topics: Developer Forum, User Forum
May 13, 2011 at 8:23 AM


I am trying to use PHPExcel (which is super great btw.) to generate, of course, an Excel file.

I have a loop which for each user in the db creates a new sheet.

So first I create the object

$objPHPExcel = new PHPExcel();

and blank sheet appears.

After this a do a loop which creates the other sheets:

foreach ($users as $user) {
    $objWorksheet1 = $objPHPExcel->createSheet();

What can I do to remove the first sheet?

Is there a way to create the PHPExcel object without creating the initial sheet?

Any hints / ideas would be appreciated!


Thank you in advance,


May 16, 2011 at 8:16 PM




May 18, 2011 at 1:22 PM

Thank you, it works!

Jan 24, 2013 at 3:00 PM
Edited Jan 24, 2013 at 3:00 PM

I was having this problem, too, and confirmed that joanmvf's suggestion worked.

I'll add the suggestion to add this at the beginning of your routine (before the foreach loop) with the following:



That way, you're guaranteed to be deleting an empty sheet and you don't have to track how many sheets you created.