|
|
|
ระบบดำเนินการ import จาก excel เข้าสู่ระบบ (ฐานข้อมูลเป็น sql server) อย่างอื่นๆเข้าปกติหมด ยกเว้นวันที่ |
|
|
|
|
|
|
|
สงสัยว่าทำไม 5/12/2013 กลายเป็น 41613 ไปได้
ไม่ทราบว่า connect กับ excel แบบไหนครับ ???
|
|
|
|
|
Date :
2013-11-11 12:19:45 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอบความคิดเห็นที่ : 1 เขียนโดย : ห้ามตอบเกินวันละ 2 กระทู้ เมื่อวันที่ 2013-11-11 12:19:45
รายละเอียดของการตอบ ::
คือไม่รู้จะอธิบายอย่างไรคะ
แต่code หน้า insert to excel เป็นแบบนี้คะ
Code (PHP)
<title>file insert to database</title>
<?php
/** PHPExcel */
require_once 'Classes/PHPExcel.php';
/** PHPExcel_IOFactory - Reader */
include 'Classes/PHPExcel/IOFactory.php';
$inputFileName = "myfile/Data.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 = 3; $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];
}
}
}
//echo '<pre>';
//var_dump($namedDataArray);
//echo '</pre><hr />';
//*** Connect to MySQL Database ***//
include "connect.php";
//echo $leasingid;
//echo $leasingproduct;
$insertDate = date('Y-m-d');
/*
$query =" SELECT *
FROM leasing
WHERE lid = '$leasingid'";
$result = mssql_query($query);
$trec=mssql_fetch_array($result);
$lid = $trec[lid];
$choosetable = $trec[lname];
//echo $choosetable;
*/
$i = 0;
foreach ($namedDataArray as $result) {
$i++;
$strSQL = "";
$strSQL .= "INSERT INTO $leasingid ";
$strSQL .= "( leasing_name
, leasing_product
, fieldteam
, call_name
, call_tell
, authorize_date
, authorize_expire
, cus_id
, contactno
, cus_name
, cus_tel
, cus_docaddress
, cus_address
, cus_currentaddress
, cus_office
, guarantor_name
, guarantor_docaddress
, guarantor_address
, guarantor_currentaddress
, guarantor_office
, guarantor_name1
, guarantor_docaddress1
, guarantor_address1
, guarantor_currentaddress1
, guarantor_office1
, car_brand
, car_type
, car_color
, car_year
, car_number
, car_province
, car_id
, car_vin
, i_behindhand
, i_date
, i_permonth
, i_totalback
, i_follow
, i_fine
, i_charge
, i_lastestpay
, i_totalpay
, i_payed
, remark
, remark1
, Status
, sm_id
, date_sent_team
, date_return_team
, type_of_sending )";
$strSQL .= "VALUES";
$strSQL .= "('".iconv("UTF-8","tis-620",$result[leasing_name])."','".iconv("UTF-8","tis-620",$result[leasing_product])."','".iconv("UTF-8","tis-620",$result[fieldteam])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[call_name])."','".iconv("UTF-8","tis-620",$result[call_tell])."','".$result[authorize_date]."','".$result[authorize_expire]."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[cus_id])."','".iconv("UTF-8","tis-620",$result[contactno])."','".iconv("UTF-8","tis-620",$result[cus_name])."','".iconv("UTF-8","tis-620",$result[cus_tel])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[cus_docaddress])."','".iconv("UTF-8","tis-620",$result[cus_address])."','".iconv("UTF-8","tis-620",$result[cus_currentaddress])."','".iconv("UTF-8","tis-620",$result[cus_office])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[guarantor_name])."','".iconv("UTF-8","tis-620",$result[guarantor_docaddress])."','".iconv("UTF-8","tis-620",$result[guarantor_address])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[guarantor_currentaddress])."','".iconv("UTF-8","tis-620",$result[guarantor_office])."','".iconv("UTF-8","tis-620",$result[guarantor_name1])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[guarantor_docaddress1])."','".iconv("UTF-8","tis-620",$result[guarantor_address1])."','".iconv("UTF-8","tis-620",$result[guarantor_currentaddress1])."','".iconv("UTF-8","tis-620",$result[guarantor_office1])."','".iconv("UTF-8","tis-620",$result[car_brand])."','".iconv("UTF-8","tis-620",$result[car_type])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[car_color])."','".iconv("UTF-8","tis-620",$result[car_year])."','".iconv("UTF-8","tis-620",$result[car_number])."','".iconv("UTF-8","tis-620",$result[car_province])."','".iconv("UTF-8","tis-620",$result[car_id])."' ";
$strSQL .= ",'".iconv("UTF-8","tis-620",$result[car_vin])."','".$result[i_behindhand]."','".$result[i_date]."','".$result[i_permonth]."' ";
$strSQL .= ",'".$result[i_totalback]."','".$result[i_follow]."','".$result[i_fine]."','".$result[i_charge]."','".iconv("UTF-8","tis-620",$result[i_lastestpay])."' ";
$strSQL .= ",'".$result[i_totalpay]."','".$result[i_payed]."','".iconv("UTF-8","tis-620",$result[remark])."','".iconv("UTF-8","tis-620",$result[remark1])."','0','0','".iconv("UTF-8","tis-620",$result[date_sent_team])."','".iconv("UTF-8","tis-620",$result[date_return_team])."','".iconv("UTF-8","tis-620",$result[type_of_sending])."')";
$strSQL1 = "";
$strSQL1 = "";
$strSQL1 .= "INSERT INTO Data_Management ";
$strSQL1 .= "( [lid]
,[contactno]
,[sm_id]
,[insert_date])";
$strSQL1 .= "VALUES";
$strSQL1 .= "('".$leasingid."','".iconv("UTF-8","tis-620",$result[contactno])."','0','".$insertDate."')";
mssql_query($strSQL) or die(mssql_error());
mssql_query($strSQL1) or die(mssql_error());
//echo $strSQL;
}
$msg= 'Insert Completed';
echo "<script type=\"text/javascript\">alert('$msg') </script>";
?>
<script type="text/javascript">
window.location="import.php";
</script>
|
|
|
|
|
Date :
2013-11-11 12:28:40 |
By :
Baitong_ch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอาออก
\\ $objReader->setReadDataOnly(true);
|
|
|
|
|
Date :
2013-11-11 13:34:47 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|