|
Server : Apache/2.2.2 (Fedora) System : Linux App1.pathumtani.go.th 2.6.20-1.2320.fc5smp #1 SMP Tue Jun 12 19:40:16 EDT 2007 i686 User : apache ( 48) PHP Version : 5.2.9 Disable Function : NONE Directory : /home/pathumthani_integration/integration/application/industry/ |
Upload File : |
<?php
header("content-type: text/html; charset=tis-620");
set_time_limit(600000);
session_start();
set_time_limit(0); # ไม่ให้ time out
require_once("../../config/config_epm.inc.php");
require_once('../../common/classXML/mysql_xml_str.class.php');
require_once "../../common/classExcel/xls_class/class.writeexcel_workbook.inc.php";
require_once "../../common/classExcel/xls_class/class.writeexcel_worksheet.inc.php";
# Variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$xlsname = "export_data.xls";
$fname = tempnam("./tmp", "tmp_demo.xls");
$workbook =& new writeexcel_workbook($fname);
$worksheet =& $workbook->addworksheet($report_date); # เพิ่ม work sheet
# End Variables - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$colors = array(
'black'=>0x08,
'blue'=>0x0C,
'brown'=>0x10,
'cyan'=>0x0F,
'gray'=>0x17,
'green'=>0x11,
'lime'=>0x0B,
'magenta'=>0x0E,
'navy'=>0x12,
'orange'=>0x35,
'purple'=>0x14,
'red'=>0x0A,
'silver'=>0x16,
'white'=>0x09,
'yellow'=>0x0D
);
# Header Styles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
$title =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$title =& $workbook->addformat();
$title->set_bold(1);
$title->set_size(10);
$title->set_top(0);
$title->set_left(0);
$title->set_bottom(0);
$title->set_align('center');
$title->set_align('vcenter');
$title->set_merge(); # This is the key feature
$title_child_cell =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$title_child_cell =& $workbook->addformat();
$title_child_cell->set_size(10);
$title_child_cell->set_top(0);
$title_child_cell->set_right(0);
$title_child_cell->set_left(0);
$title_child_cell->set_align('center');
$title_child_cell->set_align('vcenter');
$title_child_cell->set_merge(); # This is the key feature
$heading_merge =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$heading_merge =& $workbook->addformat();
$heading_merge->set_bold(1);
$heading_merge->set_size(10);
$heading_merge->set_top(1);
$heading_merge->set_left(1);
$heading_merge->set_right(1);
$heading_merge->set_bottom(1);
$heading_merge->set_align('center');
$heading_merge->set_align('vcenter');
$heading_merge->set_merge();
$heading_merge_no_top =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$heading_merge_no_top =& $workbook->addformat();
$heading_merge_no_top->set_bold(1);
$heading_merge_no_top->set_size(10);
$heading_merge_no_top->set_top(0);
$heading_merge_no_top->set_left(1);
$heading_merge_no_top->set_right(1);
$heading_merge_no_top->set_bottom(1);
$heading_merge_no_top->set_align('center');
$heading_merge_no_top->set_align('vcenter');
$heading_merge_no_top->set_merge();
$heading_merge_no_bottom =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$heading_merge_no_bottom =& $workbook->addformat(array('fg_color' =>$colors['blue']));
$heading_merge_no_bottom->set_bold(1);
$heading_merge_no_bottom->set_size(10);
$heading_merge_no_bottom->set_top(1);
$heading_merge_no_bottom->set_left(1);
$heading_merge_no_bottom->set_right(1);
$heading_merge_no_bottom->set_bottom(0);
$heading_merge_no_bottom->set_align('center');
$heading_merge_no_bottom->set_align('vcenter');
$heading_merge_no_bottom->set_merge();
$heading_merge_no_top_bottom =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$heading_merge_no_top_bottom =& $workbook->addformat();
$heading_merge_no_top_bottom->set_bold(1);
$heading_merge_no_top_bottom->set_size(10);
$heading_merge_no_top_bottom->set_top(0);
$heading_merge_no_top_bottom->set_left(1);
$heading_merge_no_top_bottom->set_right(1);
$heading_merge_no_top_bottom->set_bottom(0);
$heading_merge_no_top_bottom->set_align('center');
$heading_merge_no_top_bottom->set_align('vcenter');
$heading_merge_no_top_bottom->set_merge();
$body =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$body =& $workbook->addformat();
$body->set_size(10);
$body->set_top(1);
$body->set_left(1);
$body->set_right(1);
$body->set_bottom(1);
$body->set_align('center');
$body->set_align('vcenter');
$body_left =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$body_left =& $workbook->addformat();
$body_left->set_size(10);
$body_left->set_top(1);
$body_left->set_left(1);
$body_left->set_right(1);
$body_left->set_bottom(1);
$body_left->set_align('vcenter');
$body_left_bold =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$body_left_bold =& $workbook->addformat();
$body_left_bold->set_bold(1);
$body_left_bold->set_size(10);
$body_left_bold->set_top(1);
$body_left_bold->set_left(1);
$body_left_bold->set_right(1);
$body_left_bold->set_bottom(1);
$body_left_bold->set_align('vcenter');
$body_bold =& $workbook->addformat(array('font'=>'CordiaUPC','color'=>'black','size'=>14,'text_wrap'=>1));
$body_bold =& $workbook->addformat();
$body_bold->set_bold(1);
$body_bold->set_size(10);
$body_bold->set_top(1);
$body_bold->set_left(1);
$body_bold->set_right(1);
$body_bold->set_bottom(1);
$body_bold->set_align('center');
$body_bold->set_align('vcenter');
# End Header Styles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Write heading =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Set Column
$xlsRow = 0; # เริ่มต้นแถวที่ 0
// get column
$columnxml= "<?xml version=\"1.0\" encoding=\"$Encoding\"?>". mysql_to_xml(0, $ProfileID, "","TRUE");
$arr_column=get_object_vars( simplexml_load_string($columnxml)->rec);
// get data
$dataxml="<?xml version=\"1.0\" encoding=\"$Encoding\"?>". mysql_to_xml(0, $ProfileID, "","FALSE");
$arr_data=get_object_vars( simplexml_load_string($dataxml));
$xlsRow=0;
$col_index=0;
####################################################START write header column
foreach ($arr_column as $index=>$colname){
$worksheet->write($xlsRow,$col_index , $index, $heading_merge_no_bottom);
$col_index++;
}
################################################### END write header column
$xlsRow++;
foreach ($arr_data as $index=>$datalist){
$col_index=0;
$row=get_object_vars( $datalist);
foreach ($row as $index=>$values){
$pos = strpos($values, "::");
if ($pos === false) {
}else{
$values="";
}
$worksheet->write($xlsRow,$col_index , iconv("UTF-8","TIS-620", $values), $body);
$col_index++;
}
$xlsRow++;
}
$worksheet->set_landscape(1); #Lanscape Page
$worksheet->set_margin_left(0.35);
$worksheet->set_margin_right(0.35);
$worksheet->set_margin_top(0.35);
$worksheet->set_margin_bottom(0.35);
// $worksheet->set_paper(5); #Paper Type : Legal
$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($xlsname).";");
header("Content-Transfer-Encoding: binary ");
header("Content-Length: ".filesize($fname));
readfile($fname);
unlink($fname);
exit();
# End Send "Excel File" to "Browser" . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
?>