Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create new worksheets with PHPExcel using kohana 3.2

$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.

like image 740
Jabeen Avatar asked Feb 19 '23 23:02

Jabeen


1 Answers

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') ;
like image 71
Mark Baker Avatar answered Feb 27 '23 10:02

Mark Baker