I am using codeigniter framework, in this I am creating excel file with MySQL data's. I need to create header table (ie, first loop) data's into first sheet, detail table (ie, second loop) data's into second sheet. Below I have given my code, this generating in same sheet with next next data's. Can any one give some ideas to solve this.
$out = '"S.no","HeaderID","InvoiceID","InvoiceNo","doc_no","InvoiceDate","PartyCode","doc_type","CurrencyID","Remarks","loc_amt","doc_amt"'."\r\n";
$i=1;
foreach($export_list as $d)
{
$out .= $i.',"'.$d->slsid.'","'.'0'.'","'.$d->reference_no.'","'.' '.'","'.$d->date.'","'.$d->customer_code.'","'.' '.'","'.' '.'","'.$d->internal_note.'","'.'0'.'","'.$d->total.'"'."\r\n";
$i++;
}
$out .= '"S.no","HeaderID","DetailID","ProductID","Description","Qty","loc_amt","doc_amt"'."\r\n";
$i=1;
foreach($export_detail as $d)
{
$out .= $i.',"'.$d->sale_id.'","'.$d->id.'","'.$d->product_code.'","'.' '.'","'.$d->quantity.'","'.'0'.'","'.$d->gross_total.'"'."\r\n";
$i++;
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=Users.xls');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $out;
exit;
Thanks in advance.