Combine Multiple CSVs to Single Excel With Multiple Worksheets

Topics: User Forum
Aug 27, 2012 at 5:58 PM

What is the most efficient way to do this? We can't get much past 30,000 total rows even with a 2GB memory limit? We don't need any formatting in the Excel file. Is a particular Excel format more efficient than another? Here is what we are doing now:

 

$sheetIdx = 0;
$excel = new PHPExcel();
foreach($csvs as $tmpFile => $title)
{
	if($sheetIdx > 0)
	{
		$excel->createSheet();
	}
	$excel->setActiveSheetIndex($sheetIdx);
	$excel->getActiveSheet()->setTitle($title);

	$reader = PHPExcel_IOFactory::createReader('CSV');
	$reader->setSheetIndex($sheetIdx);
	$reader->loadIntoExisting($tmpFile, $excel);		

	$sheetIdx++;
}					

if($sheetIdx > 0)
{
	$excel->setActiveSheetIndex(0);
	$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
	$writer->save($filename, TRUE);
}