problem with several worksheets, labels and images

Topics: User Forum
Jun 20, 2011 at 7:42 PM
Edited Jun 20, 2011 at 7:45 PM


I have a problem with PHPExcel

I'm creating several sheets in a workbook using a template.
When I insert a sheet, I assign a new label for this new sheet.  The problem is when the second sheet is inserted, the name of the previous sheet is changed with the name of the sheet in the template, then, when the third sheet is inserted occur an error, and I think is because the name of the second sheet is changed with the name of the template's sheet and the worksheet don't allow to have two sheets with the same name.

The problem is that I assign diferent names for each sheet, and I don't know why every time a insert a new sheet, the names of the previous sheet are changing.

The same occurs when I insert an image in every sheet I'm creating.   When a new sheet is created, the images in the previous sheets, disapear.

To solve this, I had to rename every sheet after a new sheet was created, and when all sheets was created, I had to insert my image in every sheet in the document.

This is what I did.

$names = array();

for($count=0; $count<5; $count++){       
            $Template   = $objReader->load("template.xlsx");
            $workSheet    = $Template->getSheet(0);

            // If I don't rename the label of the previous sheets, an error occurs because the previous labels are missing and the label of the original template is showed.

                for($i=0; $i<$count; $i++){

// Finaly, I tried to insert an image in the moment that a new sheet was inserted, but at the end, only the last sheet had the image.

// Then I had to insert the image in every sheet when every sheets was created.

            $objDrawing = new PHPExcel_Worksheet_Drawing();


Could anybody help me to find out if I am doing something wrong?, and what could be the right way to do this?.

Thanks in advance.




Jun 22, 2011 at 11:13 PM


I finaly found what the problem was.

In the next line, I must put the index number of the sheet, insted the number zero.





Thanks anyway.