How to export multiple worksheets to individual excel files phpexcel

Topics: Developer Forum
Nov 11, 2012 at 12:17 AM

Am trying to export an excel file with 5 worksheets in it.

I would like to export each worksheet as an individual excel file. I have tried using the getWorksheetIterator but no success and it throws this error.

Catchable fatal error: Object of class PHPExcel_Worksheet could not be converted to string in

<!--?php //session_start(); ?-->
require_once '../Classes/PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
//echo $xlsxfiles;
$objPHPExcel = $objReader->load('../upload/Demobook.xlsx');
$num=$objPHPExcel->getSheetCount() ;
$sheetnames=$objPHPExcel->getSheetNames() ;
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow(); // e.g. 10
$objWriter = new PHPExcel_Writer_CSV($objPHPExcel);
$objReader = new PHPExcel_Reader_CSV();
 foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {



//header("Location: column_sort.php");


Nov 11, 2012 at 10:27 PM

you are trying to use a worksheet object as a string, which doesn't work. How about using the title?


$title = $worksheet->getTitle();

and use $title in the filename