我正在使用codeigniter框架,在這裏我正在用MySQL數據創建excel文件。我需要創建頭表(即第一個循環)數據到第一個工作表,細節表(即第二個循環)數據到第二個工作表中。下面我給出了我的代碼,這將生成與下一個數據相同的表單。任何人都可以提出一些想法來解決這個問題。如何自定義excel數據的兩個工作表在一個excel與PHP?
$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;
在此先感謝。
嘗試使用PHPExcel –
在PHPExcel中,您可以更改工作表添加標題到工作表等 –
爲此我需要下載PHPExcel核心文件並添加到我的模塊中嗎?然後如何形成excel文件。如果你有任何鏈接給我,我會遵循。 –