I have written an Export script that will export data from my database as a CSV or XLS file. The data from the database needs to be manipulated first. So far I have the CSV file working and am now trying to convert this CSV string to XLS. I want to use phpExcel but get the below error. Can anyone assist?
Fatal error: Class 'PHPExcel_Exception' not found in /var/www/leanne/api/library/PHPExcel/Exception.php on line 36
Code which is causing the error, all worked fine until I added the XLS stuff:
if($format == 'csv'){
//create and write to file for CSV
if(file_exists($file_location . $filename)){
unlink($file_location . $filename);
}
$fh = fopen($file_location . $filename , 'a');
fwrite($fh, $csv);
fclose($fh);
} else if($format == 'xls'){
//wite to file for XLS
include '../library/PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('CSV');
$objReader->setDelimiter($separator);
$objReader->setEnclosure(" ");
$objReader->setLineEnding($endrow);
$objPHPExcel = $objReader->load($csv);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($file_location . $filename);
}
NB: csv is a string containing comma separated and double quoted fields from the database. The lines end with '\n'.