I have the following code that exports a csv file :
//Selecting Item Data based on Date
$result = mysql_query("SELECT item_no, qty, discount_price, date
FROM sold_items WHERE date BETWEEN '".$fdate."' AND '".$tdate."'
ORDER BY date Desc");
$filename = "C:/xampp/htdocs/frame/Sales".".csv";
if(file_exists($filename)) {
$f = fopen("{$filename}", 'w');
//Fputs the Table Headers
fputcsv($f, array('Item No', 'Qty', 'Sell Price', 'Date'));
//Fputcsv adds records to csv file
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
fputcsv($f, $row);
}
//Close file
fclose($f);
}
The above code works perfectly, the problem is that i need to stop exporting csv from now on and export an xls file.
I've changed $filename into:
$filename = "C:/xampp/htdocs/frame/Sales".".xls";
The format of xls is not correct, its like all records are place inside one field in the excel file. I've tried googling and saw some complicated ways phpexcel and something that I could not understand. Is there a simple way of doing it? Maybe with /t to make each record as a seperate field in excel.