Multiple sheets from same input

Dec 2, 2008 at 11:38 PM
I am inputting 2 different Excel files, and outputting 1 file.

The file I am creating to output will have between 1 and 50 sheets (depending on database results)

The first file I input occupys sheet 1 in the output file.

The second file I input occupys all the other (sheets 2-50)

As now, I have everything doing what I want, but the only way I can get to duplicate the second input file to all the sheets is:

$objPHPExcel2 = $objReader->load("file.xlsx");
$objPHPExcel3 = $objReader->load("file.xlsx");
$objPHPExcel4 = $objReader->load("file.xlsx");
$objPHPExcel5 = $objReader->load("file.xlsx");
$objPHPExcel6 = $objReader->load("file.xlsx");
$objPHPExcel7 = $objReader->load("file.xlsx");

ie load the file in up to 50 times. (which can't be ideal!!!)

I can do all the sheet generation etc. - but I want to be able to do something like:

$objPHPExcel2 = $objReader->load("file.xlsx");
$objPHPExcel3=$objPHPExcel2;
$objPHPExcel4=$objPHPExcel2;
$objPHPExcel5=$objPHPExcel2;
$objPHPExcel6=$objPHPExcel2;
$objPHPExcel7=$objPHPExcel2;

etc. --  but I cant...

what should I do?
Developer
Dec 2, 2008 at 11:54 PM
Let me see if I understand you.... File 1 contains one single sheet, file 2 contains also one sheet. These are your template files.

The final workbook should consist of the sheet from file 1 + up to perhaps 50 duplications of the single sheet from file 2.

Basically, it sounds like you are trying to copy a worksheet and merge two workbooks?

Copying a sheet within a workbook:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=7157

Merging workbooks:
http://www.codeplex.com/PHPExcel/Thread/View.aspx?ThreadId=36984