Create Multiple Sheet PHPExcel

 $obj = new Excel();

 while ($i < 10) {

// Add new sheet
 $objWorkSheet = $obj->createSheet($i); //Setting index when creating

//Write cells
 $objWorkSheet->setCellValue('A1', 'Hello'.$i)
 ->setCellValue('B2', 'world!')
 ->setCellValue('C1', 'Hello')
 ->setCellValue('D2', 'world!');

// Rename sheet


 $filename='just_some_random_name.xls'; //save our workbook as this file name
 header('Content-Type: application/'); //mime type
 header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
 header('Cache-Control: max-age=0'); //no cache

//save it to Excel5 format (excel 2003 .XLS file), change this to 'Excel2007' (and adjust the filename extension, also the header mime type)
 //if you want to save it as .XLSX Excel 2007 format
 $objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel5');
 //force user to download the Excel file without writing it to server's HD


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: