Export Excel อย่างง่ายกับ PHP
Posted by on 10th, 2008
ดูโค้ดก่อนแล้วกัน
<?php
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment; filename="MyXls.xls"');#ชื่อไฟล์
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<HTML>
<HEAD>
<meta http-equiv="Content-type" content="text/html;charset=tis-620" />
</HEAD><BODY>
<TABLE x:str BORDER="1">
<TR>
<TD><b>AAA</b></TD>
<TD><b>AAA</b></TD>
<TD><b>AAA</b></TD>
</TR>
<TR>
<TD>BBB</TD>
<TD>BBB</TD>
<TD>BBB</TD>
</TR>
<TR>
<TD>001</TD>
<TD>002</TD>
<TD>003</TD>
</TR>
<TR>
<TD>ภาษาไทย</TD>
<TD>ภาษาไทย</TD>
<TD>ภาษาไทย</TD>
</TR>
</TABLE>
</BODY>
</HTML>
จุดหลักๆมีอยู่ 3 จุด
1. แป่ะ Header เพื่อบอกว่าจะเปิดไฟล์ Excel
<?phpheader("Content-Type: application/vnd.ms-excel");header('Content-Disposition: attachment; filename="MyXls.xls"');#ชื่อไฟล์?>
2.ส่วนนี้มีผลกับการแสดง Excel จำเป็นมาก
<html xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:x="urn:schemas-microsoft-com:office:excel"xmlns="http://www.w3.org/TR/REC-html40">
3. อันนี้แหล่ะที่จะทำให้ข้อมูลที่นำหน้าด้วยเลขศูนย์แสดงขึ้นมา เพราะกำหนดให้เป็น String
<TABLE x:str BORDER="1">
ตัวอย่าง คลิกที่นี่
ดาวน์โหลด คลิกที่นี่
อ่านเพิ่มเติมได้ที่นี่ครับ (อธิบายดีจริงๆ) : http://sixhead.com/2008/03/06/easy-export-to-excel/



เป็นประโยชน์มากๆ ขอบคุณสำหรับข้อความนี้มากๆค่ะ
ถ้าไม่ได้ข้อความนี้ คงต้องทำอีกนาน แสนนาน…
October 27th, 2008 at 1:55 pm
thank you very much
October 29th, 2008 at 6:50 pm
ทำมั๊ยต้องพึ่ง http://www.w3.org/TR/REC-html40 ด้วยอะ
March 27th, 2009 at 11:00 am
มาตรฐานของ html น่ะครับ เป็นมาตรฐานไว้ไม่เสียหลาย
March 27th, 2009 at 8:19 pm
[…] เข้าไปอ่านได้ที่นี่ค่ะ http://www.memo8.com/toolkits/archives/78 […]
May 14th, 2009 at 12:57 pm
Thank ^^
June 30th, 2009 at 12:00 pm