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 > มีปัญหา เมื่อ Export to Excel แล้วชื่อคอลัมที่กำหนดเป็นภาษาไทย กลายเป็นภาษาต่างดาวคับ?



 

มีปัญหา เมื่อ Export to Excel แล้วชื่อคอลัมที่กำหนดเป็นภาษาไทย กลายเป็นภาษาต่างดาวคับ?

 



Topic : 049341

Guest




Code (PHP)
<?
require_once "class/class.writeexcel_workbook.inc.php";
require_once "class/class.writeexcel_worksheet.inc.php";


$host="localhost";
$username="root";
$password="1234";
$dbname="icaddy_db";
$link=mysql_connect($host,$username,$password);
mysql_connect("$host","$username","$password") or die ("CAN NOT CONNECT TO SERVER");
mysql_query("SET NAMES	tis620");
mysql_select_db($dbname,$link) or die ("CAN NOT TO FINE DATABASE");

$fname= "Report.xls";
$workbook =& new writeexcel_workbook($fname);

$worksheet =& $workbook->addworksheet("Report");
$worksheet->set_margin_right(0.50);
$worksheet->set_margin_bottom(1.10);

## Set Format ##

$xlscelldesc_header =& $workbook->addformat();
$xlscelldesc_header->set_font('MS Sans Serif');
$xlscelldesc_header->set_size(10);
$xlscelldesc_header->set_color('blue');
$xlscelldesc_header->set_bold(1);
$xlscelldesc_header->set_text_v_align(1);
$xlscelldesc_header->set_merge(1);

$xlsCellDesc =& $workbook->addformat();
$xlsCellDesc->set_font('MS Sans Serif');
$xlsCellDesc->set_size(8);
$xlsCellDesc->set_color('black');
$xlsCellDesc->set_align('left');
$xlsCellDesc->set_text_v_align(1);

## End of Set Format ##



## Set Column Width & Height กำหนดความกว้างของ Cell

$worksheet->set_column('A:A', 10);
$worksheet->set_column('B:B', 10);
$worksheet->set_column('C:C', 20);
$worksheet->set_column('D:D', 10);
$worksheet->set_column('E:E', 10);
$worksheet->set_column('F:F', 10);
$worksheet->set_column('G:G', 10);
$worksheet->set_column('H:H', 10);
$worksheet->set_column('I:I', 10);
$worksheet->set_column('J:J', 10);
$worksheet->set_column('K:K', 22);
$worksheet->set_column('L:L', 8);


$celldesc_h = 16.50;


## Writing Data เพิ่มข้อมูลลงใน Cell



# กำหนดความสูงของ Cell

$worksheet->set_row(1, $celldesc_h); 

$worksheet->set_row(2, $celldesc_h);

$worksheet->set_row(3, $celldesc_h);

$worksheet->set_row(4, $celldesc_h);

$worksheet->set_row(5, $celldesc_h);




$worksheet->write(G3, " title",$xlscelldesc_header);
$worksheet->write_blank(F6,$xlscelldesc_header);


$worksheet->write(A5,"No.", $xlscelldesc_header); 
$worksheet->write(B5,"Golfer ID", $xlscelldesc_header); 
$worksheet->write(C5,"Name Golfer", $xlscelldesc_header); 
$worksheet->write(D5,"Telephone", $xlscelldesc_header);
$worksheet->write(E5,"โทร.1", $xlscelldesc_header);
$worksheet->write(F5,"โทร.2", $xlscelldesc_header);
$worksheet->write(G5,"โทร.3", $xlscelldesc_header);
$worksheet->write(H5,"โทร.4", $xlscelldesc_header);
$worksheet->write(I5,"โทร.5", $xlscelldesc_header);
$worksheet->write(J5,"ทีม", $xlscelldesc_header);
$worksheet->write(K5,"อีเมล์", $xlscelldesc_header);
$worksheet->write(L5,"เพศ", $xlscelldesc_header);

$xlsRow = 6;



# ตรงนี้คือดึงข้อมูลจาก mysql มาใส่ใน Cell
$sql="select golferID,name,telephone,telephone1,telephone2,telephone3,telephone4,telephone5,teamID,sex,email from golfer"; 

$query=mysql_query($sql);
$num=mysql_num_rows($query);
if($num==0){
echo "ไม่พบข้อมูล";
print "<meta http-equiv=refresh content='0;URL=admin_1.php'>"; 

exit();
}else{
$count=1;
				while($result= mysql_fetch_array($query)){
++$i;  


$worksheet->set_row($xlsRow, 19.80);
$worksheet->write("A$xlsRow", $count, $xlsCellDesc);
$worksheet->write("B$xlsRow", $result["golferID"], $xlsCellDesc); // ติดที่ตัวนี้ ถ้าไม่ใส่ \r ตัวข้างหน้าจะไม่มีช่องว่าง แต่เลข 0 ข้างหน้า จะถูกตัดทิ้งไป
$worksheet->write("C$xlsRow", "\r".$result["name"], $xlsCellDesc);
$worksheet->write("D$xlsRow", "\r".$result["telephone"], $xlsCellDesc); 
$worksheet->write("E$xlsRow", "\r".$result["telephone1"], $xlsCellDesc);
$worksheet->write("F$xlsRow", "\r".$result["telephone2"], $xlsCellDesc);
$worksheet->write("G$xlsRow", "\r".$result["telephone3"], $xlsCellDesc);
$worksheet->write("H$xlsRow", "\r".$result["telephone4"], $xlsCellDesc);
$worksheet->write("I$xlsRow", "\r".$result["telephone5"], $xlsCellDesc);
$worksheet->write("J$xlsRow", $result["teamID"], $xlsCellDesc);
$worksheet->write("K$xlsRow", $result["email"], $xlsCellDesc);
$worksheet->write("L$xlsRow", $result["sex"], $xlsCellDesc);
$count=$count+1;
$xlsRow++;


}
}

# เสร็จแล้วก็ส่งไฟล์ไปยัง Browser ครับแค่นี้ก็เสร็จแล้ว

$workbook->close();

header("Pragma:  no-cache");
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("Report_Golfer.xls").";");
header("Content-Type: text/html; charset=tis-620");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($fname));
readfile($fname); 
unlink($fname);

exit();

?>




คอลัมที่ผมกำหนดเป็นภาษาไทยเอาไว้
Code (PHP)
$worksheet->write(K5,"อีเมล์", $xlscelldesc_header);
$worksheet->write(L5,"เพศ", $xlscelldesc_header);


จากโค๊ด เมื่อ Export สำเร็จก็กลายเป็นภาษาต่างดาวคับ เช่น เธญเธตเน€เธกเธฅเนŒ
ภาษาต่างดาว
แต่ข้อมูลจาก database ที่เป็นไทยออกได้ตามปกติคับ ติดแต่คอลัมที่กำหนดไทยเท่านั้นคับ
รบกวนผู้รู้ ผู้เชี่ยวชาญ ชำนาญการ ตอบด้วยครับ ขอขอบคุณล่วงหน้าคับผม



Tag : PHP, Excel (Excel.Application)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-09-25 18:36:38 By : Thotsaporn View : 3772 Reply : 9
 

 

No. 1



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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


header("Content-Type: text/html; charset=utf-8");






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 18:41:27 By : PlaKriM
 


 

No. 2

Guest


ตอบความคิดเห็นที่ : 1 เขียนโดย : PlaKriM เมื่อวันที่ 2010-09-25 18:41:27
รายละเอียดของการตอบ ::
ผมใส่แล้วนะคับ แต่ก็ยังไม่ออกเหมือนเดิมคับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 20:24:39 By : Thotsaporn
 

 

No. 3



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

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


file ที่ gen excel เป็น ansi หรือ utf หรืออะไรครับ

ถ้าไม่ได้จริงๆ คงต้องใช้ iconv ช่วยนะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 20:44:37 By : PlaKriM
 


 

No. 4

Guest


ตอบความคิดเห็นที่ : 3 เขียนโดย : PlaKriM เมื่อวันที่ 2010-09-25 20:44:37
รายละเอียดของการตอบ ::
อืมม ไม่ทราบอ่ะคับ แล้วดูยังไงอ่ะคับว่าเป็น ansi หรือ utf อ่ะคับ?
และการใช้ iconv ใช้ยังไงเหรอคับ ผมรบกวนด้วยนะคับ.

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 22:07:56 By : Thotsaporn
 


 

No. 5

Guest


ตอบความคิดเห็นที่ : 3 เขียนโดย : PlaKriM เมื่อวันที่ 2010-09-25 20:44:37
รายละเอียดของการตอบ ::
เป็น UTF-8 คับผม

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 22:38:34 By : Thotsaporn
 


 

No. 6

Guest


ป่านฉะนี้ผมยังแก้ไม่ได้เลยอ่ะคับ?
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-10-03 14:45:10 By : Thotsaporn
 


 

No. 7



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



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


require_once "class/class.writeexcel_workbook.inc.php";
require_once "class/class.writeexcel_worksheet.inc.php";


เรียกใช้ files include จากไหนครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-04 14:35:24 By : owenss
 


 

No. 8



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

ตอบความคิดเห็นที่ : 7 เขียนโดย : owenss เมื่อวันที่ 2014-03-04 14:35:24
รายละเอียดของการตอบ ::
PHPExcel กับ Reader การอ่านไฟล์ Excel (.xls,.xlsx) และการนำเข้าฐานข้อมูล MySQL


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-03-04 15:03:26 By : mr.win
 


 

No. 9



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



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

ลองอันนี้ดูนะครับ

http://www.appservnetwork.com/modules.php?name=News&file=article&sid=2
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-16 11:55:39 By : Hayaak Solution
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : มีปัญหา เมื่อ Export to 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 03
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 อัตราราคา คลิกที่นี่