<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
//Convert number to words
if ( ! function_exists('excel')){
	
	function excel($bodyData){
		//Excell download ready
		$CI =& get_instance();
		$CI->load->library('parser');
		$myFile = str_replace(" ", "_",$bodyData['excelTitle']).".xls";
		//pass retrieved data into template and return as a string
		$stringData = $CI->parser->parse('layouts/report/header', $bodyData, true);
		$stringData .= $CI->parser->parse('layouts/report/excel', $bodyData, true);
		
		//open excel and write string into excel
		$fh = fopen($myFile, 'w') or die("can't open file");
		fwrite($fh, $stringData);
		
		fclose($fh);
		//download excel file
		header("Content-Length: " . filesize($myFile));
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment; filename='.$myFile);
		
		readfile($myFile);
	}
}
?>
