轉出 Excel 或 CSV

1 篇文章 / 0 new
author
轉出 Excel 或 CSV
► html 直接輸出
header("Content-type: application/vnd.ms-excel; charset = UTF8");
header("Content-Disposition: inline; filename = 00.xls ;");
header('Cache-Control: public');
echo "<style> .nf { mso-number-format:\"\@\"; } </style>";
echo "<table>";
echo "<tr><td>供應商</td><td> vd[sn]['COMPANYNAME']</td>";
echo "    <td>生效日期</td><td class=nf> vd[sn]['ACTIVE_DATE']</td>";
echo "    <td>運送方式</td><td> this->shippingList[vd[sn]['SHIPPING']] </td></tr>";
echo "<tr><td>報價主題</td><td>vd[sn]['SUBJECT']</td>";
echo "    <td>失效日期</td><td class=nf> vd[sn]['INACTIVE_DATE'] </td>";        
echo "    <td>付款方式</td><td>this->paymentList[vd[sn]['PAYMENT']] </td></tr>";        
echo "<tr><td>聯絡人</td><td  class=nf> vd[sn]['CONTACTUSER'] / vd[sn]['MTEL'] </td>";
echo "    <td>公司電話</td><td  class=nf>vd[sn]['TEL'] </td>";        
echo "    <td>公司傳真</td><td  class=nf>vd[sn]['FAX'] </td></tr>";
echo "</table>";
► Create a CSV file
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=user_signups.csv');
header('Pragma: no-cache');
header('Expires: 0');
$output = fopen('php://output', 'w');
fputcsv($output, array("a","b","c"));
fputcsv($output, array(""));
fputcsv($output, array("","a","b"));
fputcsv($output, array("a","b"));
fputcsv($output, array("a","","c"));
fclose($output);
Free Web Hosting