cloned sheets along with other sheets in single file

Topics: Developer Forum, Project Management Forum, User Forum
May 26, 2010 at 10:40 AM

Hi,

               I am now trying to have a three sheet  template file where the first sheet and last should be there as such, but the middle one  should be copied and there should be ten cloned sheets between the first and third,

But the problem is i could clone the sheets but the cloned sheets always comes at the first position even when the sheet index is changed. I tried with various combination of fixing the sheet in the right position.

For ex :  Template File will have => FIRST MIDDLE LAST

                Template File will have => FIRST MIDDLE(1-10)  LAST

                Output File I Get =>FIRST OVERRIDDEN MIDDLE, MIDDLE CLONE 1, LAST OVERRIDDENT MIDDLE, MIDDLE CLONE 4-7

Is this possible  to i do, what i am expecting.

Plese help me

 

Thanks

Coordinator
May 27, 2010 at 9:00 AM
$objPHPExcel = PHPExcel_IOFactory::load('Template.xls');
$sheet = $objPHPExcel->getSheetByName('Middle')->setTitle('Middle 1');
for ($i = 2; $i < 5; $i++) {
    $sheet = $objPHPExcel->getSheetByName('Middle 1')->copy();
    $sheet->setTitle('Middle '.$i);
    $sheet->setCellValue('A1', 'B'.$i);
    $objPHPExcel->addSheet($sheet);
    $objPHPExcel->setIndexByName('Middle '.$i,$i);
}
$objPHPExcel->setActiveSheetIndex(0);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('NewTemplate.xls');