|
 |
|
ทำไมถึงไม่แสดงรูปแบบตาราง Excel......ผู้รู้ช่วยตอบหรือแก้ปัญหาข้อผิดพลาดด้วยค่ะ |
|
 |
|
|
 |
 |
|
ทำไมเขียนโค้ด report ให้แสดงออกมารูปแบบ Excel แล้วไม่ขึ้น ใครช่วยดูข้อผิดพลาดให้หน่อยได้มั้ยค่ะ (เขียนใน Dreamweaver CS4 ใช้ภาษาที่เขียนคือ PHP ) ตอนกดรันแสดงผลหน้าเว็บ ขึ้นข้อความว่า ผิดบรรทัดที่ 5
Code (PHP)
<?
include('../connect.php');
require_once('phpexcel/class.writeexcel_format.inc.php');
require_once('phpexcel/class.writeexcel_workbook.inc.php');
require_once('phpexcel/class.writeexcel_worksheet.inc.php'); // <=========================
$token = md5(uniqid(rand(), true));
$fname= "tmp/$token.xls";
$workbook =& new writeexcel_workbook($fname);
$worksheet =& $workbook->addworksheet("Report PK-Watch.com");
$worksheet->set_margin_right(0.5);
$worksheet->set_margin_bottom(0.5);
$worksheet->set_margin_top(0.5);
$worksheet->set_margin_left(0.5);
$date_array_start=explode("-",$startdate);
$date_array_end=explode("-",$enddate);
$xlscell =& $workbook->addformat();
$xlscell->set_font('Angsana New');
$xlscell->set_size('22');
$xlscell->set_color('black');
$xlscell->set_bold(1);
$xlscell->set_text_v_align(1);
$xlscell->set_merge(1);
$xlscelldesc_header =& $workbook->addformat();
$xlscelldesc_header->set_font('Angsana New');
$xlscelldesc_header->set_size('18');
$xlscelldesc_header->set_color('black');
$xlscelldesc_header->set_bold(1);
$xlscelldesc_header->set_text_v_align(1);
$xlscelldesc_header->set_merge(1);
//$xlscelldesc_header->set_border(1,1,1,1);
//$xlscelldesc_header->set_border_color('black');
///////////////////////////////////////////////////////////
$xlsCellDesc =& $workbook->addformat();
$xlsCellDesc->set_font('Angsana New');
$xlsCellDesc->set_size('16');
$xlsCellDesc->set_color('black');
$xlsCellDesc->set_text_v_align(1);
## End of Set Format ##
## Set Column Width & Height
$worksheet->set_column('A:B',11);
$worksheet->set_column('B:C',11);
$worksheet->set_column('C:D',25);
$worksheet->set_column('D:E',15);
$worksheet->set_column('E:F',15);
$worksheet->set_column('F:G',15);
$worksheet->set_column('G:H',15);
$worksheet->set_column('H:I',15);
//$worksheet->set_column('I:J',4);
$celldesc_h = 21;
$worksheet->set_row(0,34);
for($a=0;$a<=2000;$a++){
$worksheet->set_row($a, $celldesc_h);
}//for(a=0;a>=26;a++){
$worksheet->write(B1,"Sales report on ".$date_array_start[2]."/".$date_array_start[1]."/".$date_array_start[0]." to ".$date_array_end[2]."/".$date_array_end[1]."/".$date_array_end[0], $xlscell);
$worksheet->write_blank(C1,$xlscell);
$worksheet->write_blank(D1,$xlscell);
$worksheet->write_blank(E1,$xlscell);
$worksheet->write_blank(F1,$xlscell);
$worksheet->write_blank(G1,$xlscell);
//$worksheet->write(D2,"àÇÅÒ/Time",$xlscelldesc_header);
//$worksheet->write(E2,"$status1",$xlscelldesc_header);
///////////////////////////////////////////////////////////////////
$worksheet->write(A3,"ÃËÑÊÊÑ觫×éÍ",$xlscelldesc_header);
$worksheet->write(B3,"ÃËÑÊÊÁÒªÔ¡",$xlscelldesc_header);
$worksheet->write(C3,"ª×èͼÙéÊÑ觫×éÍ",$xlscelldesc_header);
$worksheet->write(D3,"Çѹ·ÕèÊÑ觫×éÍ",$xlscelldesc_header);
$worksheet->write(E3,"¨Ó¹Ç¹ªÔé¹",$xlscelldesc_header);
$worksheet->write(F3,"ÃÒ¤ÒÃÇÁ",$xlscelldesc_header);
$worksheet->write(G3,"Çѹ·ÕèªÓÃÐà§Ô¹",$xlscelldesc_header);
$worksheet->write(H3,"Çѹ·Õè¨Ñ´Êè§",$xlscelldesc_header);
/*****************************************4444****************************************/
$xlsrow=4;
$sql="select * from tb_order where date_payment >='$startdate' and date_payment <='$enddate'";//echo $sql;
$rs=mysql_db_query($dbname,$sql) or die("Can not concect data base");
while($rc=mysql_fetch_array($rs)){
$order_id=sprintf("%05d",$rc['id_order']);
$member_id=sprintf("%05d",$rc['id_member']);
$name_order=$rc['name_order'];
$date_order=$rc['date_order'];
$total_price=$rc['total_order'];
$date_payment=$rc['date_payment'];
$date_delivery=$rc['date_delivery'];
$sql_piece="select sum(number) as sum_piece from tb_order_detail where ref_id_order='$order_id'";
$rs_piece=mysql_db_query($dbname,$sql_piece) or die("Can not concect data base");
$rc_piece=mysql_fetch_array($rs_piece);
$total_piece=$rc_piece['sum_piece'];
$worksheet->write("A$xlsrow","'"."$order_id",$xlsCellDesc);
$worksheet->write("B$xlsrow","'"."$member_id",$xlsCellDesc);
$worksheet->write("C$xlsrow","$name_order",$xlsCellDesc);
$worksheet->write("D$xlsrow","$date_order",$xlsCellDesc);
$worksheet->write("E$xlsrow","$total_piece",$xlsCellDesc);
$worksheet->write("F$xlsrow","$total_price",$xlsCellDesc);
$worksheet->write("G$xlsrow","$date_payment",$xlsCellDesc);
$worksheet->write("H$xlsrow","$date_delivery",$xlsCellDesc);
$xlsrow=$xlsrow+1;
}// while($row=mssql_fetch_array($rs)){
$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("report.xls").";");
header("Content-Transfer-Encoding: binary ");
header("Content-Length: ".filesize($fname));
readfile($fname);
unlink($fname);
exit();
?>
Tag : PHP, MySQL, Excel (Excel.Application)

|
|
 |
 |
 |
 |
Date :
2012-05-18 21:14:48 |
By :
Gibzy |
View :
1292 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
|
|

|
Load balance : Server 05
|