|
 |
|
แปลงตัวเลขให้เป็นวันที่ ต้องทำไงค่ะพลิกแผ่นดินแล้วไม่ได้เลย ช่วยด้วยค่ะ |
|
 |
|
|
 |
 |
|
คุณ Import ผ่านอะไรครับ
|
 |
 |
 |
 |
Date :
2012-06-15 17:40:45 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำการ Import .xls ผ่าน php เข้าไปเก็บที่ sql server ค่ะ
ใน field start_date data type เป็น datetime
ใน excel file colum start_date มีข้อมูลเป็น 22/11/2006 10:00:00 AM
แต่พอ Import เข้า database แล้ว ดันเป็น 39043.41667
ก้อเลยงง เลยค่ะ ไปไหนไม่ถูก
รบกวนพี่วินช่วยด้วยค่ะ
ขอบคุณล่วงหน้าค่ะ
|
 |
 |
 |
 |
Date :
2012-06-16 08:34:51 |
By :
paphun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดู Code หน่อยครับ 
|
 |
 |
 |
 |
Date :
2012-06-16 10:54:24 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
session_start();
require("include/connect.php");
require("include/function.php");
$today=date("d-m-Y H:i:s");
$date=date("dmY");
switch($_GET[type]){
case "Select" :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form name="frmGETRTBS" action="import.php?type=ImportRTBS" method="post">
<table>
<tr><td><a href="javascript:document.frmGETRTBS.submit();"><img src="images/submit.gif" border="0" /></a></td></tr>
</table>
</form>
break;
case "ImportRTBS" :
/** PHPExcel */
require_once 'Classes/PHPExcel.php';
/** PHPExcel_IOFactory - Reader */
include 'Classes/PHPExcel/IOFactory.php';
$inputFileName = "D:\RTBS\RTBS.xls";
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($inputFileName);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$headingsArray = $objWorksheet->rangeToArray('A1:'.$highestColumn.'1',null, true, true, true);
$headingsArray = $headingsArray[1];
$r = -1;
$namedDataArray = array();
for ($row = 2; $row <= $highestRow; ++$row) {
$dataRow = $objWorksheet->rangeToArray('A'.$row.':'.$highestColumn.$row,null, true, true, true);
if ((isset($dataRow[$row]['A'])) && ($dataRow[$row]['A'] > '')) {
++$r;
foreach($headingsArray as $columnKey => $columnHeading) {
$namedDataArray[$r][$columnHeading] = $dataRow[$row][$columnKey];
}
}
}
$i = 0;
foreach ($namedDataArray as $result) {
$i++;
$TableRTBSIns = "tbl_rtbs";
$FieldRTBSIns = "Site,[Order No],[Line No],[Del No],[Line Item No],[RTBS Line Item No],[Customer PO No],Reference,[Sales Part No],Description,";
$FieldRTBSIns.= "Type,Customer,[Customer Name],[Customer Product Code],[Customer Product Description],[Delay By],[Delay Cause],[Delay Description],";
$FieldRTBSIns.= "[Customer Line Status],[Shop Order Status],Export,RTBS,[Original RTBS],[Changed Date],[Changed By],[Original Lot Size],[Lot Size],";
$FieldRTBSIns.= "[Pre pack ],[Log Pack],[Shop Order Qty Completed],[Qty Delivered],[Remaining Delivered Qty],[Package Type],Copyright,[Purge Order],";
$FieldRTBSIns.= "Coordinator,[Coordinator Name],Sound,[Sound Description],[Sales Type],[Sales Description],[Print Part Group],[Print Part Group Description],";
$FieldRTBSIns.= "Country,[Ship to Address],[New Master],user_log";
$ValueRTBSIns = "'".$result["Site"]."','".$result["Order No"]."','".$result["Line No"]."','".$result["Del No"]."','".$result["Line Item No"]."',";
$ValueRTBSIns.= "'".$result["RTBS Line Item No"]."','".$result["Customer PO No"]."','".$result["Reference"]."','".$result["Sales Part No"]."',";
$ValueRTBSIns.= "'".$result["Description"]."','".$result["Type"]."','".$result["Customer"]."','".$result["Customer Name"]."','".$result["Customer Product Code"]."',";
$ValueRTBSIns.= "'".$result["Customer Product Description"]."','".$result["Delay By"]."','".$result["Delay Cause"]."','".$result["Delay Description"]."',";
$ValueRTBSIns.= "'".$result["Customer Line Status"]."','".$result["Shop Order Status"]."','".$result["Export"]."','".$result["RTBS"]."','".$result["Original RTBS"]."',";
$ValueRTBSIns.= "'".$result["Changed Date"]."','".$result["Changed By"]."','".$result["Original Lot Size"]."','".$result["Lot Size"]."','".$result["Pre pack "]."',";
$ValueRTBSIns.= "'".$result["Log Pack"]."','".$result["Shop Order Qty Completed"]."','".$result["Qty Delivered"]."','".$result["Remaining Delivered Qty"]."',";
$ValueRTBSIns.= "'".$result["Package Type"]."','".$result["Copyright"]."','".$result["Purge Order"]."','".$result["Coordinator"]."','".$result["Coordinator Name"]."',";
$ValueRTBSIns.= "'".$result["Sound"]."','".$result["Sound Description"]."','".$result["Sales Type"]."','".$result["Sales Description"]."',";
$ValueRTBSIns.= "'".$result["Print Part Group"]."','".$result["Print Part Group Description"]."','".$result["Country"]."','".$result["Ship to Address"]."',";
$ValueRTBSIns.= "'".$result["New Master"]."','".$_SESSION[u_user]."'";
$objRTBSIns = funInsert($TableRTBSIns,$FieldRTBSIns,$ValueRTBSIns);
}
echo "<script>alert('Delete and Insert OK');window.location='index.php';</script>";
mssql_close($objConnect);
break;}
RTBS.xls ข้อมูลในกรอบสี่เหลี่ยมที่มีปัญหาเรื่อง datetime อยู่ค่ะ

|
 |
 |
 |
 |
Date :
2012-06-16 13:19:52 |
By :
paphun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลืมบอกรายละเอียดเพิ่มค่ะ
ส่วนของ RTBS.xls
Format cell เป็น Custom (dd/mm/mm h:mm)
ส่วนของ Database
Field DataType
RTBS Datetime
[Original RTBS] Datetime
[Changed Date] Datatime
เงื่อนไข
1.เราไม่สามารถเปลี่ยน Format cell ของ excel file ได้ค่ะ เนื่องมาจาก export มาจากอีกระบบค่ะ
2. ถ้าลองเปลี่ยน Format cell เป็น General ก้อจะได้เป็นตัวเลข เช่น 22/11/2006 10:00:00 AM เปลี่ยนแล้วเป็น 39043.4166666667 และมันจะเอาค่านี้ไปลงใน Database อีกด้วย ซึ้งมันผิด
|
 |
 |
 |
 |
Date :
2012-06-16 13:36:34 |
By :
paphun |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สรุปว่าทำได้หรือยังค่ะ ติดปัญหานี้อยู่เหมือนกัน
|
 |
 |
 |
 |
Date :
2012-09-25 00:03:01 |
By :
comp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|