<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>S i X h E a D { ? } &#187; editplus</title>
	<atom:link href="http://sixhead.com/tag/editplus/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixhead.com</link>
	<description>เมื่อความรู้มีไว้แบ่งปัน</description>
	<lastBuildDate>Mon, 27 Feb 2012 06:23:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Export เป็น Excel อย่างด่วน</title>
		<link>http://sixhead.com/2008/03/06/easy-export-to-excel/</link>
		<comments>http://sixhead.com/2008/03/06/easy-export-to-excel/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 16:29:55 +0000</pubDate>
		<dc:creator>Pipo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[editplus]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[header]]></category>

		<guid isPermaLink="false">http://sixhead.com/2008/03/06/export-to-excel/</guid>
		<description><![CDATA[ในงานหลายๆ งานที่ต้องมีการ export ข้อมูลออกมา เมื่อก่อนงูๆ ปลาๆ แค่ทำเป็น csv ต่อมาเริ่มหาเครื่องมือช่วยแล้วก็ได้ php_writeexcel ดูตัวอย่างการทำงาน ได้ที่นี่ เป็น class ที่ช่วยสร้าง excel จริงๆ ขึ้นมาได้ ซึ่งใช้ได้ดีมากๆ แต่ในบางครั้งแค่ต้องการ export ข้อมูลอย่างเดียวเราสามารถใช้วิธีสร้างไฟล์ excel ง่ายๆ จาก code html ได้เลย ดูตัวอย่าง ได้ที่นี่ มาดู code กัน &#60;? $strExcelFileName = &#34;Excel ไฟล์ง่ายนิดเดียว.xls&#34;; header&#40;&#34;Content-Type: application/x-msexcel; name=\&#34;$strExcelFileName\&#34;&#34;&#41;; header&#40;&#34;Content-Disposition: inline; filename=\&#34;$strExcelFileName\&#34;&#34;&#41;; header&#40;&#34;Pragma: no-cache&#34;&#41;; ?&#62; ส่วนนี้เป็น header ของ server (website) เพื่อบอก client (browser [...]]]></description>
			<content:encoded><![CDATA[<p>ในงานหลายๆ งานที่ต้องมีการ export ข้อมูลออกมา เมื่อก่อนงูๆ ปลาๆ แค่ทำเป็น csv ต่อมาเริ่มหาเครื่องมือช่วยแล้วก็ได้ <a href="http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/">php_writeexcel</a> ดูตัวอย่างการทำงาน <a href="http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/demo/">ได้ที่นี่</a> เป็น class ที่ช่วยสร้าง excel จริงๆ ขึ้นมาได้ ซึ่งใช้ได้ดีมากๆ แต่ในบางครั้งแค่ต้องการ export ข้อมูลอย่างเดียวเราสามารถใช้วิธีสร้างไฟล์ excel ง่ายๆ จาก code html ได้เลย </p>
<p><span id="more-34"></span> ดูตัวอย่าง <a href="http://sixhead.com/testrun/php/export/easy-excel.php">ได้ที่นี่</a> มาดู code กัน </p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #0000ff;">$strExcelFileName</span>	=	<span style="color: #ff0000;">&quot;Excel ไฟล์ง่ายนิดเดียว.xls&quot;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Type: application/x-msexcel; name=<span style="color: #000099; font-weight: bold;">\&quot;</span>$strExcelFileName<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Content-Disposition: inline; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>$strExcelFileName<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Pragma: no-cache&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
<p>ส่วนนี้เป็น header ของ server (website) เพื่อบอก client (browser IE,FireFox, etc..) ว่าเอกสารที่กำลังเรียกมานี้เป็น excel เรื่อง header นี้ถ้ารักจะเป็น web developer จำเป็นต้องรู้นะครับ ทำอะไรได้มากมายเลย  เช่น debug program ที่เกี่ยวกับ www, debug flash + php ฯลฯ จะทำให้ทำงานได้เร็วขึ้นเยอะ หรือรวมไปถึงเรื่อง hack เลยทีเดียว ไว้เรื่อง header จะขอแยกเป็นอีกเรื่องหนึ่งในภายหลังครับ</p>
<pre class="html4strict"><span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html</span></a> xmlns:o=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:office:office&quot;</span>
xmlns:x=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:office:excel&quot;</span>
xmlns=<span style="color: #ff0000;">&quot;http://www.w3.org/TR/REC-html40&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/html.html"><span style="color: #000000; font-weight: bold;">&lt;html&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/head.html"><span style="color: #000000; font-weight: bold;">&lt;head&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/meta.html"><span style="color: #000000; font-weight: bold;">&lt;meta</span></a> <span style="color: #000066;">http-equiv</span>=<span style="color: #ff0000;">&quot;Content-type&quot;</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">&quot;text/html;charset=tis-620&quot;</span> /<span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/style.html"><span style="color: #000000; font-weight: bold;">&lt;style</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;SiXhEaD_Excel_Styles&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/style&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">&lt;body&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>ตัวอย่างรายงาน<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/br.html"><span style="color: #000000; font-weight: bold;">&lt;br&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">&lt;div</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;SiXhEaD_Excel&quot;</span> <span style="color: #000066;">align</span>=center x:publishsource=<span style="color: #ff0000;">&quot;Excel&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/table.html"><span style="color: #000000; font-weight: bold;">&lt;table</span></a> x:str <span style="color: #000066;">border</span>=<span style="color: #cc66cc;">0</span> <span style="color: #000066;">cellpadding</span>=<span style="color: #cc66cc;">0</span> <span style="color: #000066;">cellspacing</span>=<span style="color: #cc66cc;">0</span> <span style="color: #000066;">width</span>=<span style="color: #cc66cc;">100</span>% <span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;border-collapse: collapse&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;50&quot;</span> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>Id<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;80&quot;</span> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>จังหวัด<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;80&quot;</span> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span><span style="color: #009900;"><a href="http://december.com/html/4/element/strong.html"><span style="color: #000000; font-weight: bold;">&lt;strong&gt;</span></a></span>โทรศัพท์<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/strong&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span>00001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span>กรุงเทพฯ<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span>0810000000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/tr.html"><span style="color: #000000; font-weight: bold;">&lt;tr&gt;</span></a></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span>00002<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span>กาญจนบุรี<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/td.html"><span style="color: #000000; font-weight: bold;">&lt;td</span></a> <span style="color: #000066;">class</span>=xl2216681 nowrap&gt;</span>0819999999<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/td&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tr&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html&gt;</span></span></pre>
<p> ส่วนนี้เป็น tag html ล้วนๆ มีสิ่งที่พิเศษอยู่หน่อยตรง 3 บรรทัดแรกที่ระบุว่า รูปแบบของไฟล์นี้เป็น excel</p>
<pre>class=xl2216681</pre>
<p>ใส่เลข random อะไรก็ได้แต่ให้เหมือนกันทั้งหน้า</p>
<p>จะเอาไปใช้งานก็ดูตัวอย่างดีๆ นะครับ tag บางอันถ้าไม่มีก็ยังออกมาเป็น excel ได้ แต่ว่าบาง column ที่มี 0 นำหน้าเลข 0 จะหายไปครับ</p>
<p>ทิ้งท้าย<br />
- <a href="http://sixhead.com/testrun/php/export/easy-excel.phps">source code</a><br />
- ตัว phpmyadmin ที่เราๆ ท่านๆ ใช้กันอยู่ก็ใช้วิธี export ออกเป็น excel ด้วยวิธีนี้เช่นกัน<br />
- ผมแนะนำนะครับว่า พวกไฟล์ทั้งหลายอย่าไปคิดว่ามันเปิดด้วย excel หรือ word ได้เท่านั้น ลองเอา editplus หรือ notepad เปิดไฟล์ .xls ที่ได้จากวิธีการนี้ดูแล้วคุณจะประหลาดใจกับมันครับ เรื่องเปิดไฟล์ใดๆ ด้วย editplus ยังทำให้คุณแปลกใจอะไรได้อีกมากมาย ลองดูแล้วกันครับ</p>
<p><map name='google_ad_map_34_f21c57aff87a446f'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/34?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_34_f21c57aff87a446f' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=34&amp;url= http%3A%2F%2Fsixhead.com%2F2008%2F03%2F06%2Feasy-export-to-excel%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://sixhead.com/2008/03/06/easy-export-to-excel/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

