Export Excel อย่างง่ายกับ PHP

Posted by admin 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/

6 Responses to “Export Excel อย่างง่ายกับ PHP”

  1. หนอนทราย

    เป็นประโยชน์มากๆ ขอบคุณสำหรับข้อความนี้มากๆค่ะ

    ถ้าไม่ได้ข้อความนี้ คงต้องทำอีกนาน แสนนาน…


  2. so good

    thank you very much


  3. zekoza

    ทำมั๊ยต้องพึ่ง http://www.w3.org/TR/REC-html40 ด้วยอะ


  4. admin

    มาตรฐานของ html น่ะครับ เป็นมาตรฐานไว้ไม่เสียหลาย


  5. COOL CCS » Blog Archive » Excel กับ PHP

    […] เข้าไปอ่านได้ที่นี่ค่ะ http://www.memo8.com/toolkits/archives/78 […]


  6. Amy

    Thank ^^


Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word



ค้นหาแบบธรรมดา


ค้นหาแบบเทพฯ ให้พี่ Google ช่วยเลย


ขอแป่ะหน่อย

sidebanner sidebanner sidebanner

SUBSCRIBE

Stumble
Digg
Technorati
Reddit
Delicious