4
$excel2 = PHPExcel_IOFactory::createReader('Excel2007');
$excel2 = $excel2->load('ExampleSpreadsheettest.xlsx'); 
$excel2->setActiveSheetIndex(0);
$excel2->getActiveSheet()->setCellValue('A4', 'first page')
        ->setCellValue('A1', '5')
        ->setCellValue('A2', '6')       
        ->setCellValue('A3', '7');
$objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007');
$objWriter->save('ExampleNew.xlsx');

Above code is working but i want to add more worksheets instead of single work sheet.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Jabeen
  • 357
  • 2
  • 4
  • 15

1 Answers1

8

Reading the PHPExcel documentation might help: the addSheet() method is used to add a new worksheet.

$excel2->addSheet();
$excel2->setActiveSheetIndex(1);  
$excel2->getActiveSheet()->setCellValue('A4', 'second page') ;
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 2
    Just use: $excel2->createSheet(1); //where 1 is the number of the worksheet (counting from zero!)... or see PHPExcel - creating multiple sheets by iteration http://stackoverflow.com/questions/9850013/phpexcel-creating-multiple-sheets-by-iteration – Adrian P. Dec 03 '13 at 20:51