<?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; backend</title>
	<atom:link href="http://sixhead.com/tag/backend/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixhead.com</link>
	<description>เมื่อความรู้มีไว้แบ่งปัน</description>
	<lastBuildDate>Wed, 28 Jul 2010 04:21:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Export เป็น Microsoft Word อย่างด่วน</title>
		<link>http://sixhead.com/2008/09/28/easy-export-to-microsoft-word/</link>
		<comments>http://sixhead.com/2008/09/28/easy-export-to-microsoft-word/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 16:17:23 +0000</pubDate>
		<dc:creator>Pipo</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[backend]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[word]]></category>

		<guid isPermaLink="false">http://sixhead.com/?p=188</guid>
		<description><![CDATA[ระบบ Program หน้า backend ของการเขียนโปรแกรมนั้น โดยทั่วไปแล้วการมี หน้าสรุป, หน้ารายงานข้อมูลต่างๆ ถือเป็นหัวใจสำคัญทีเดียว การสร้างมูลค่าเพิ่ม (ให้งานดูดีมีระดับและได้เงินค่าจ้างเพิ่มขึ้น) ก็คือการสร้างรายงานที่เป็น Microsoft Excel, Microsoft Word นั่นเองเนื่องจาก ไฟล์ 2 ประเภทนี้สามารถส่งต่อไปยังผู้ที่เกี่ยวข้องได้ง่ายกว่า การที่ต้องมานั่ง login ทุกครั้งที่อยากดูข้อมูล พูดมากไปแล้วมาเข้าเรื่องกันเลย คราวนี้ถือเป็นภาคต่อจากบทความ Export เป็น Excel อย่างด่วน บทความนี้ดูตัวอย่าง ได้ที่นี่ มาดู code กัน PHP ส่วนหัวเป็นการสร้าง header เพื่อให้ browser รู้ว่าเอกสารหน้านี้เป็น Microsoft Word &#60;?php $strWordFileName = &#34;Word ไฟล์ง่ายนิดเดียว.doc&#34;; header&#40;&#34;Content-Type: application/vnd.ms-word; name=\&#34;$strWordFileName\&#34;&#34;&#41;; header&#40;&#34;Content-Disposition: inline; filename=\&#34;$strWordFileName\&#34;&#34;&#41;; header&#40;&#34;Pragma: no-cache&#34;&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>ระบบ Program หน้า backend ของการเขียนโปรแกรมนั้น โดยทั่วไปแล้วการมี หน้าสรุป, หน้ารายงานข้อมูลต่างๆ ถือเป็นหัวใจสำคัญทีเดียว การสร้างมูลค่าเพิ่ม (ให้งานดูดีมีระดับและได้เงินค่าจ้างเพิ่มขึ้น) ก็คือการสร้างรายงานที่เป็น Microsoft Excel, Microsoft Word นั่นเองเนื่องจาก<br/><span id="more-188"></span> ไฟล์ 2 ประเภทนี้สามารถส่งต่อไปยังผู้ที่เกี่ยวข้องได้ง่ายกว่า การที่ต้องมานั่ง login ทุกครั้งที่อยากดูข้อมูล พูดมากไปแล้วมาเข้าเรื่องกันเลย คราวนี้ถือเป็นภาคต่อจากบทความ <a href="http://sixhead.com/2008/03/06/easy-export-to-excel">Export เป็น Excel อย่างด่วน</a> บทความนี้ดูตัวอย่าง <a href="http://sixhead.com/testrun/php/export/easy-word.php">ได้ที่นี่</a> มาดู code กัน</p>
<p>PHP ส่วนหัวเป็นการสร้าง header เพื่อให้ browser รู้ว่าเอกสารหน้านี้เป็น Microsoft Word
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #0000ff;">$strWordFileName</span>    =    <span style="color: #ff0000;">&quot;Word ไฟล์ง่ายนิดเดียว.doc&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/vnd.ms-word; name=<span style="color: #000099; font-weight: bold;">\&quot;</span>$strWordFileName<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>$strWordFileName<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>ส่วนบนของ HTML ด้านล่างนี้ บอกว่าเอกสารต่อไปนี้ชนิดเป็นอะไร ซึ่งก็คือ Microsoft Word นั่นเอง ส่วนเนื้อหากลางๆ หน้าดูให้ดีก็คือ HTML ล้วนๆ
<pre class="html4strict">&nbsp;
<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:word&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;"><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>
&nbsp;
ทดลองสร้างไฟล์ Microsoft Word จาก HTML<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/table.html"><span style="color: #000000; font-weight: bold;">&lt;table</span></a> <span style="color: #000066;">border</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">cellpadding</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">cellspacing</span>=<span style="color: #ff0000;">&quot;1&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/th.html"><span style="color: #000000; font-weight: bold;">&lt;th</span></a> <span style="color: #000066;">bgcolor</span>=<span style="color: #ff0000;">&quot;#96BB00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Field<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/th.html"><span style="color: #000000; font-weight: bold;">&lt;th</span></a> <span style="color: #000066;">bgcolor</span>=<span style="color: #ff0000;">&quot;#FFFF99&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/b.html"><span style="color: #000000; font-weight: bold;">&lt;b&gt;</span></a></span>Type<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/b&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th&gt;</span></span>
<span style="color: #009900;"><a href="http://december.com/html/4/element/th.html"><span style="color: #000000; font-weight: bold;">&lt;th</span></a> <span style="color: #000066;">bgcolor</span>=<span style="color: #ff0000;">&quot;#96BB00&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #009900;"><a href="http://december.com/html/4/element/b.html"><span style="color: #000000; font-weight: bold;">&lt;b&gt;</span></a></span>Null<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/b&gt;</span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/th&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&gt;</span></a></span><span style="color: #009900;"><a href="http://december.com/html/4/element/b.html"><span style="color: #000000; font-weight: bold;">&lt;b&gt;</span></a></span>ConnectId<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/b&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&gt;</span></a></span>int(10)<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&gt;</span></a></span>Yes<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&gt;</span></a></span>MachineName<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&gt;</span></a></span>varchar(50)<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&gt;</span></a></span>Yes<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&gt;</span></a></span>HDModel<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&gt;</span></a></span>varchar(50)<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&gt;</span></a></span>Yes<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>
&nbsp;
<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/font.html"><span style="color: #000000; font-weight: bold;">&lt;font</span></a> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;#339900&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>ใช้งานกับภาษาไทยได้ดีทีเดียว<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/font&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>จากตัวอย่างจะเห็นได้ง่ายๆ เลยว่าเราพลิกจากหน้า report ธรรมดา สร้างมูลค่าเพิ่มให้มันกลายเป็น Microsoft Word ได้ในพริบตาทีเดียว ดาวน์โหลด <a href="http://sixhead.com/testrun/php/export/easy-word.phps">source code ได้ที่นี่</a></p>
<p><map name='google_ad_map_188_f21c57aff87a446f'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/188?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_188_f21c57aff87a446f' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=188&amp;url= http%3A%2F%2Fsixhead.com%2F2008%2F09%2F28%2Feasy-export-to-microsoft-word%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://sixhead.com/2008/09/28/easy-export-to-microsoft-word/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
