Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > php export เป็น excel แล้วฟอแมตเพี้ยน แก้ยังไงครับ



 

php export เป็น excel แล้วฟอแมตเพี้ยน แก้ยังไงครับ

 



Topic : 108584

Guest




ส่วนโค๊ด

Code (PHP)
<?PHP ob_start();?>
<?PHP
		include("connect/connect.php"); 
		include_once("class/php_writeexcel-0.3.0/class.writeexcel_worksheet.inc.php");
		include_once("class/php_writeexcel-0.3.0/class.writeexcel_workbook.inc.php");

		$st_date = $_POST[st_date];
		$end_date = $_POST[end_date];		
		
		$token = md5( uniqid(rand(), true ) );
		$fname= "tmp/$token.xls";
		$workbook =& new writeexcel_workbook($fname);
		$worksheet =& $workbook->addworksheet("Test");
		$worksheet->set_margin_right(0.50);
		$worksheet->set_margin_bottom(1.10);
			
		## Set Format  ##
		$xlscelldesc_header =& $workbook->addformat();
		$xlscelldesc_header->set_font('Angsana New');
		$xlscelldesc_header->set_size(14);
		$xlscelldesc_header->set_color('black');
		$xlscelldesc_header->set_bold(1);
		$xlscelldesc_header->set_align('left');
		$xlscelldesc_header->set_text_v_align(1);
		$xlscelldesc_header->set_merge(1);
		
		$xlsCellDesc =& $workbook->addformat();
		$xlsCellDesc->set_font('Angsana New');
		$xlsCellDesc->set_size(14);
		$xlsCellDesc->set_color('black');
		$xlsCellDesc->set_bold(0);
		$xlsCellDesc->set_align('left');
		$xlsCellDesc->set_text_v_align(1);
		## End of Set Format ##
		
		## Set Column Width & Height  to Cell
		$worksheet->set_column('A:B',10);
		$worksheet->set_column('B:C',8);
		$worksheet->set_column('C:D',10);
		$worksheet->set_column('D:E',10);
		$worksheet->set_column('E:F',10);
		$worksheet->set_column('F:G',13);
		$worksheet->set_column('G:H',10);
		$worksheet->set_column('H:I',10);
		$worksheet->set_column('I:J',10);
		$worksheet->set_column('J:K',10);
		$celldesc_h = 10;
		
		//หัวคอลัมม์
		$xlsRow = 1;
		$worksheet->set_row($xlsRow,$celldesc_h);
		$worksheet->write("A$xlsRow","ลำดับ", $xlscelldesc_header);
		$worksheet->write("B$xlsRow","จังหวัด", $xlscelldesc_header); 
		$worksheet->write("C$xlsRow","สาขา", $xlscelldesc_header);
		$worksheet->write("D$xlsRow","ชื่อ-สกุล", $xlscelldesc_header);
		$worksheet->write("E$xlsRow","เพศ", $xlscelldesc_header);
		$worksheet->write("F$xlsRow","หมายเลขโทรศัพท์", $xlscelldesc_header);
		$worksheet->write("G$xlsRow","อีเมล์", $xlscelldesc_header);
		$worksheet->write("H$xlsRow","ยี่ห้อรถ", $xlscelldesc_header);
		$worksheet->write("I$xlsRow","รุ่น", $xlscelldesc_header);
		$worksheet->write("J$xlsRow","ปีรุ่น", $xlscelldesc_header);
		$xlsRow++;	
		$no_format =& $workbook->addformat(array(num_format => '0'));
		$no_format->set_align('center');
		$character =& $workbook->addformat();
		$sql = "SELECT 
		request_customer.rcust_id,
		request_customer.rcust_fullname,
		REPLACE(REPLACE(request_customer.rcust_gender,'M','ชาย'),'F','หญิง') AS GENDER,
		request_customer.rcust_email,
		request_customer.rcust_dateadd,
		INSERT(INSERT(request_customer.rcust_telephone,7,0,'-'),4,0,'-') AS telephone, 
		request_customer.rcust_brand,
		request_customer.rcust_model,
		request_customer.rcust_myear,
		depart.depart as rcust_province,
		depart_sub.depart_sub as rcust_branch
		FROM request_customer 
		INNER JOIN depart ON request_customer.rcust_province = depart.id
		INNER JOIN depart_sub ON request_customer.rcust_branch = depart_sub.id
		WHERE date(request_customer.rcust_dateadd) BETWEEN  '$st_date' AND  '$end_date' 
		ORDER BY request_customer.rcust_dateadd";
		$Query = mysql_query($sql);
		//$countNo=1;
		while($rows = mysql_fetch_array($Query))
		{
			
			$worksheet->set_row($xlsRow, 15.80);
			//$worksheet->write("A$xlsRow", $countNo, $character);
			$worksheet->write("B$xlsRow", $rows['rcust_province'], $character); 
			$worksheet->write("C$xlsRow", $rows['rcust_branch'], $character);
			$worksheet->write("D$xlsRow", $rows['rcust_fullname'], $character); 
			$worksheet->write("E$xlsRow", $rows['rcust_gender'], $character);
			$worksheet->write("F$xlsRow", $rows['rcust_telephone'], $character);
			$worksheet->write("G$xlsRow", $rows['rcust_email'], $character);
			$worksheet->write("H$xlsRow", $rows['rcust_brand'], $character);
			$worksheet->write("I$xlsRow", $rows['rcust_model'], $character);
			$worksheet->write("J$xlsRow", $rows['rcust_myear'], $character);
			$xlsRow++;	
			//$countNo++;
		}
//Save as Excel						
$workbook->close();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename('Rcust_'.$st_date.'_'.$end_date.'.xls').";");
header("Content-Transfer-Encoding: UTF-8");
header("Content-Length: ".filesize($fname));
readfile($fname); 
unlink($fname);
exit();
?>
<?php
ob_end_flush();
?>


และส่วนที่ได้ใน excel
Code
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" /> ะฯเกฑแ>   l ษTestBไ=ผ%r8X"1ศArial1ศArial1ศArial1ศArial1ศArial1ศ Arial1ผ Angsana New1 Angsana Newเ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ๕ @ภ เ @ภ เ Hภ เHภ เHภ เ"@ภ เ @ภ “€’โ8€€€€€€€€€ภภภ€€€™™™3fฬฬff€€fฬฬฬ€€€€€€ฬฬฬฬ™™ฬ™ฬฬ™ฬ™3f3ฬฬ™ฬฬ™fff™–––3f3™f333™3™3f33™333… ฏTest l ษU} ธ } ธ} ธ } ธ } ธ } ธ } ธ } ธ }  ธ } ธ *+‚มก"dXXเ?เ?  ศภเธฅเธณเธ”เธฑเธšเธˆเธฑเธ‡เธซเธงเธฑเธ” เธชเธฒเธ‚เธฒ!เธŠเธทเนˆเธญ-เธชเธเธธเธฅ เน€เธžเธจ5-เธซเธกเธฒเธขเน€เธฅเธ‚เน‚เธ—เธฃเธจเธฑเธžเธ—เนŒเธญเธตเน€เธกเธฅเนŒ เธขเธตเนˆเธซเน‰เธญเธฃเธ– เธฃเธธเนˆเธ™ เธ›เธตเธฃเธธเนˆเธ™<ภ กำแพงเพชรคลองลาน tess pheon f fee ๚ฃ@<ภ กาฬสินธุ์ กาฬสินธุ์ tess pheon f fee ๚ฃ@)š™™™™™๑?(๐?'เ?&่?„ƒ> ถ Root EntryBook 




Tag : PHP, Excel (Excel.Application)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-05-23 09:59:25 By : T_Programmer View : 2106 Reply : 2
 

 

No. 1



โพสกระทู้ ( 27 )
บทความ ( 0 )



สถานะออฟไลน์


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

ลองดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-05-23 10:40:06 By : Some one
 


 

No. 2

Guest


ลองแล้ว error แบบนี้ครับ

Code
Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 106 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 107 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 108 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 109 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 110 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 111 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 112 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 113 Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php:2) in C:\AppServ\www\muangthaileasing.co.th\rep_rcust_curdate.php on line 114 ��ࡱ�>�� �������� ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ l �TestB�=�%r8X"1���Arial1���Arial1���Arial1���Arial1���Arial1� �Arial1� Angsana New1� Angsana New��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� ��� @� � @� � H� �H� �H� �"@� � @� �����8�������������������������������3f������ff���f����������������������������������̙��̙3f�3���������fff����3f3�f333�3�3f33�333� �Test l �U} � } �} � } � } � } � } � } � }  � } � *+����"dXX�?�?  ��ลำดับจังหวัด สาขา!ชื่อ-สกุล เพศ5-หมายเลขโทรศัพท์อีเมล์ ยี่ห้อรถ รุ่น ปีรุ่น<� ��ᾧྪ���ͧ�ҹ tess pheon f fee ��@<� ����Թ��� ����Թ��� tess pheon f fee ��@)�������?(�?'�?&�?��> � Root Entry������������Book ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-05-23 10:43:07 By : T_PROGRAMMER
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : php export เป็น excel แล้วฟอแมตเพี้ยน แก้ยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 01
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่