|
|
|
export excel แล้วภาษาไทยเป็นสี่เหลี่ยมค่ะ ช่วยหน่อยนะคะด่วนมากๆเลย |
|
|
|
|
|
|
|
Code (PHP)
<?php
ob_start();
?>
<? $host = "localhost" ;
$username = "root" ;
$password = "root" ;
$db = "m_db" ;
mysql_connect($host,$username,$password);
?>
<?
require_once "../../Classes/class.writeexcel_workbook.inc.php";
require_once "../../Classes/class.writeexcel_worksheet.inc.php";
$token = md5(uniqid(rand(), true));
$fname= "$token.xls";
$workbook =& new writeexcel_workbook($fname);
$worksheet =& $workbook->addworksheet("Curve");
$workbook->set_codepage(3); //*******set codepage = utf-8*******
$worksheet->set_margin_right(0.50);
$worksheet->set_margin_bottom(1.10);
## Set Format ##
$xlscelldesc_header =& $workbook->addformat();
$xlscelldesc_header->set_font('Tahoma');
$xlscelldesc_header->set_size(14);
$xlscelldesc_header->set_color('BLUE');
$xlscelldesc_header->set_bold(1);
$xlscelldesc_header->set_align('center');
$xlscelldesc_header->set_text_v_align(1);
// $xlscelldesc_header->set_merge(1);
$xlscelldesc_header2 =& $workbook->addformat();
$xlscelldesc_header2->set_font('Tahoma');
$xlscelldesc_header2->set_size(16);
$xlscelldesc_header2->set_color('BLUE');
$xlscelldesc_header2->set_bold(1);
$xlscelldesc_header2->set_align('center');
$xlscelldesc_header2->set_text_v_align(1);
$xlscelldesc_header2->set_merge(1);
//$xlscelldesc_header2->set_fg_color('orange');
$xlsCellDesc =& $workbook->addformat();
$xlsCellDesc->set_font('Tahoma');
$xlsCellDesc->set_size(14);
$xlsCellDesc->set_color('black');
$xlsCellDesc->set_bold(0);
$xlsCellDesc->set_align('left');
$xlsCellDesc->set_text_v_align(1);
// $xlsCellDesc->set_merge(0);
## End of Set Format ##
## Set Column Width & Height กำหนดความกว้างของ Cell
$worksheet->set_column('A:B', 4);
$worksheet->set_column('B:C', 4);
$worksheet->set_column('C:D', 15);
$worksheet->set_column('D:E', 50);
$worksheet->set_column('E:F', 10);
$worksheet->set_column('F:G', 12);
$worksheet->set_column('G:H', 10);
$worksheet->set_column('H:I', 16);
$celldesc_h = 16.50;
## Writing Data เพิ่มข้อมูลลงใน Cellง
//$worksheet->write_blank(A1,$xlscelldesc_header2);
/*$worksheet->write_blank(D1,$xlscelldesc_header2);
$worksheet->write_blank(C1,$xlscelldesc_header2);
$worksheet->write(B1,"Transaction", $xlscelldesc_header2);
$worksheet->write_blank(E1,$xlscelldesc_header2);
$worksheet->write_blank(F1,$xlscelldesc_header2);
$worksheet->write_blank(G1,$xlscelldesc_header2);
$worksheet->write_blank(H1,$xlscelldesc_header2);*/
# กำหนดความสูงของ 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_blank(B4, $xlscelldesc_header);
// $worksheet->write(D4, " $courseno ", $xlscelldesc_header);
$worksheet->write(0, 0,"ก", $xlscelldesc_header);
$worksheet->write(0,1,"ข", $xlscelldesc_header);
$worksheet->write(0,2,"น", $xlscelldesc_header);
$worksheet->write(0,3,"ย",$xlscelldesc_header);
$worksheet->write(0,4,"ห", $xlscelldesc_header);
$worksheet->write(0,5,"ฟ ", $xlscelldesc_header);
$worksheet->write(0,6,"อ", $xlscelldesc_header);
$xlsRow = 2;
# ตรงนี้คือดึงข้อมูลจาก mysql มาใส่ใน Cell
$sql = "select * from curve";
$result = mysql_db_query($db,$sql);
while ($row = mysql_fetch_array($result)) {
$barcode= $row['curve_no'];
$status= $row['km_start'];
$date2 = $row['m_start'];
$time2= $row['km_end'];
$time= $row['m_end'];
$num= $row['curve_stl'];
$id= $row['curve_radius'];
++$i;
$worksheet->set_row($xlsRow, 19.80);
$worksheet->write("A$xlsRow", "$i", $xlsCellDesc);
$worksheet->write("B$xlsRow", "$barcode", $xlsCellDesc);
$worksheet->write("C$xlsRow", "$status", $xlsCellDesc);
$worksheet->write("D$xlsRow", "$date2", $xlsCellDesc);
$worksheet->write("E$xlsRow", "$time2", $xlsCellDesc);
$worksheet->write("F$xlsRow", "$time", $xlsCellDesc);
$worksheet->write("G$xlsRow", "อออออออออออ", $xlsCellDesc);
$xlsRow++;
}
# เสร็จแล้วก็ส่งไฟล์ไปยัง Browser
$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($fname).";");
header("Content-Transfer-Encoding: binary ");
header("Content-Length: ".filesize($fname));
readfile($fname);
unlink($fname);
exit();
?>
โค้ดค่ะ
มันเป็นเฉพาะภาษาไทยอ่าค่ะ มีสี่เหลี่ยมข้างหลัง
Tag : PHP, MySQL, Excel (Excel.Application)
|
|
|
|
|
|
Date :
2011-09-22 16:17:21 |
By :
litle |
View :
1471 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
icon()
|
|
|
|
|
Date :
2011-09-22 23:50:30 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|