Multiple sheets from same input

Dec 3, 2008 at 12:38 AM
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");

etc. --  but I cant...

what should I do?
Dec 3, 2008 at 12:54 AM
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:

Merging workbooks: