Re-using $objPHPExcel Objects ???

Topics: Developer Forum, Project Management Forum, User Forum
Aug 20, 2008 at 12:17 PM
Edited Aug 20, 2008 at 2:41 PM
I have a script that loops through a large number of organizations that I pull from a table.  Each organization gets it's own copy of an excel file that is specific to that organization while the template for the excel file starts out the same.  The problem I am having is that the memory of my script is growing huge because I need load the template file for each organization ($objPHPExcel = $objReader->load($import_file);).  Origially I tried to load the file once into a master $objPHPExcel object and just copy or clone that object for each organization, but it seems that whatever changes you do to a copy also change the master $objPHPExcel object (even though it would seem that says that that should not happen). 

So my question is:

Is there a way to create a $objPHPExcel object that you can keep pristine as a template object that you could reuse in the same script without altering the original $objPHPExcel?


**UPDATE:  I see there is a similar "Issue" at the workbook level that is addressed here: 
Is there any plans for a "copy" function for an entire PHPExcel object?
Aug 20, 2008 at 2:27 PM
Edited Aug 20, 2008 at 2:27 PM
Here is a small example you can use to see the issue:

$objPHPExcel = new PHPExcel();
$objPHPExcel2 = clone $objPHPExcel;

$objPHPExcel->getSheet(0)->setTitle("objPHPExcel Title");
print "\$objPHPExcel Sheet 1 Title = ".$objPHPExcel->getSheet(0)->getTitle()."<br>";
//Shows "objPHPExcel Title"
$objPHPExcel2->getSheet(0)->setTitle("objPHPExcel2 Title");
print "\$objPHPExcel2 Sheet 1 Title = ".$objPHPExcel2->getSheet(0)->getTitle()."<br>";
//Shows "objPHPExcel2 Title"
print "\$objPHPExcel Sheet 1 Title = ".$objPHPExcel->getSheet(0)->getTitle()."<br>";
//Shows "objPHPExcel2 Title", but seems like it should still show "objPHPExcel Title"