Booking導入數據

<?php include "../db_user.php";?> Book訂單導入

Booking導入數據

請覈對以下數據,是否與excle中的一樣,不能用空行。

<?php ini_set('memory_limit','640M'); set_time_limit(600); require_once "../class/main.class.php"; require_once "../PHPExcel-1.8/Classes/PHPExcel.php"; class MyExcel extends PHPExcel{ //擴展名範圍 public $ext=array("xls","xlsx"); //導入文件是否合法 public function valid($str){ $y=1; //取後半擴展名 $str=explode(".",$str);
			foreach($this->ext as $key =>$value){
				if(!strcmp($str[1],$value)){$y=0;}	
			}
			return $y;
		}//valid
		//解析excel
		public function read($f){
			//從文件加載excel
			$excel=PHPExcel_IOFactory::load($f);
			//得到活動的工作表
			$sheet=$excel->getActiveSheet();
			/**讀取excel文件中的第一個工作表*/ 
			$currentSheet = $excel->getSheet(0); 				
			//得到有幾條數據
			$highestRow=$sheet->getHighestRow();
			//循環讀取數據
			//因爲第一行是標題,所以從2開始
			
			$highestColumn = $sheet->getHighestColumn(); // 取得總列數						
		
			$end_index=PHPExcel_Cell::columnIndexFromString($highestColumn);//列名轉列數
			$arr=array();
			for ($row = 1; $row <= $highestRow; $row++){//第1行開始
				$j=0;					
			    for ($column = 0; $column <$end_index-1; $column++) {//列數是以A列開始
			//    		$cell=$sheet->getCellByColumnAndRow(ord($column) - 65,$row)->getValue();/**ord()將字符轉爲十進制數*/ 

			  //  	        if($cell instanceof PHPExcel_RichText){//富文本轉換字符串  
        			//			$cell = $cell->__toString();
        			//		}
					$col_name=PHPExcel_Cell::stringFromColumnIndex($column);
			$cell=$sheet->getCell($col_name.$row)->getFormattedValue();
			    	$arr[$row][$j] = $cell;
			    	$j++;
			    }
			}				
			return $arr;
		}//read

public function insertD($array,$number,$operator){
	$count=0;
	$total=0;;

	//insert into db
	$M=new Main();

date=date=M->date();
foreach($array as $t){

		$arr=array();
		$arr["number"]=$number;

arr[&quot;customer&quot;]=addslashes(arr[&quot;customer&quot;]=addslashes(t[0]);arr[&quot;supplier&quot;]=addslashes(arr[&quot;supplier&quot;]=addslashes(t[1]);arr[&quot;orderNumber&quot;]=&quot;&quot;;arr[&quot;orderNumber&quot;]=&quot;&quot;;arr[“materialCode”]=addslashes("");arr[&quot;cartonNumber&quot;]=&quot;&quot;;arr[&quot;cartonNumber&quot;]=&quot;&quot;;arr[“PONumber”]=addslashes(t[3]);t[3]);arr[“productName”]=addslashes("");arr[&quot;productCode&quot;]=&quot;&quot;;arr[&quot;productCode&quot;]=&quot;&quot;;arr[“SKU”]=addslashes(t[4]);t[4]);arr[“SKUName”]="";arr[&quot;UPC&quot;]=addslashes(arr[&quot;UPC&quot;]=addslashes(t[9]);arr[&quot;factory&quot;]=addslashes(arr[&quot;factory&quot;]=addslashes(t[2]);arr[&quot;description&quot;]=addslashes(arr[&quot;description&quot;]=addslashes(t[11]);arr[&quot;style&quot;]=addslashes(arr[&quot;style&quot;]=addslashes(t[5]);arr[&quot;styleName&quot;]=addslashes(arr[&quot;styleName&quot;]=addslashes(t[10]);arr[&quot;COO&quot;]=addslashes(arr[&quot;COO&quot;]=addslashes(t[17]);arr[&quot;lot&quot;]=addslashes(arr[&quot;lot&quot;]=addslashes(t[14]);arr[&quot;color&quot;]=addslashes(arr[&quot;color&quot;]=addslashes(t[6]);arr[&quot;colorCode&quot;]=addslashes(arr[&quot;colorCode&quot;]=addslashes(t[7]);arr[&quot;size&quot;]=addslashes(arr[&quot;size&quot;]=addslashes(t[8]);arr[&quot;others&quot;]=&quot;&quot;;arr[&quot;others&quot;]=&quot;&quot;;arr[“length”]="";arr[&quot;width&quot;]=&quot;&quot;;arr[&quot;width&quot;]=&quot;&quot;;arr[“height”]="";arr[&quot;weightG&quot;]=&quot;&quot;;arr[&quot;weightG&quot;]=&quot;&quot;;arr[“weightN”]="";arr[&quot;volume&quot;]=&quot;&quot;;arr[&quot;volume&quot;]=&quot;&quot;;arr[“price”]=t[15];t[15];arr[“currency”]=addslashes(t[16]);t[16]);arr[“qtyPerCarton”]="";arr[&quot;qty&quot;]=arr[&quot;qty&quot;]=t[12];arr[&quot;receivedQty&quot;]=&quot;&quot;;arr[&quot;receivedQty&quot;]=&quot;&quot;;arr[“receivedDate”]=addslashes(t[13]);t[13]);arr[“created”]=date;date;arr[“remark”]=addslashes($t[18]);

		$arr["operator"]=$operator;

		if($M->insert("order_detail",$arr)){//插入成功了
			$count++;
		}//if
		$total++;
	}//foreach
	echo "<script>alert('共有".$total."條數據,成功導入".$count."條.');window.location.href='../orderInput.php';</script>";
}//insert

}//Excel

$value=array();
$i=1;
if(isset($_POST["leadExcel"])){		
	//1.是不是excle
	$obj=new MyExcel();
	if($obj->valid($_FILES['fileName']['name'])){

// exit ‘<script">alert(“Only accept excel file!”);window.history.back();’;
}
//2.從第二行開始讀
value=value=obj->read($_FILES[‘fileName’][‘tmp_name’]);
SESSION[data]=serialize(_SESSION[&#x27;data&#x27;] = serialize(value);

title=&quot;&lt;th&gt;&lt;/th&gt;&quot;;for(title=&quot;&lt;th&gt;行&lt;/th&gt;&quot;; for(t=0;t&lt;31;t&lt;31;t++){
if($t<26){
title.=&quot;&lt;th&gt;&quot;.chr(65+title.=&quot;&lt;th&gt;&quot;.chr(65+t)."";
}else{
title.=&quot;&lt;th&gt;A&quot;.chr(title.=&quot;&lt;th&gt;A&quot;.chr(t+39)."";
}//if
}//for
echo ‘

’.title.&lt;/tr&gt;;foreach(title.&#x27;&lt;/tr&gt;&#x27;; foreach (value as $key => KaTeX parse error: Expected '}', got 'EOF' at end of input: …ho '<tr><td>'.(i++).’’;
foreach($value AS k=&gt;k=&gt;v){
echo ‘’;
}//foreach
echo ‘’;
}//foreach
echo ‘
’.value[value[k].’
’;
}//for
?>

系統訂單號:<?=$_REQUEST["systemBookNumber"];?>

if(isset($_GET[‘m’])){

$objIn=new MyExcel();
$objIn->insertD(unserialize($_SESSION['data']),$_REQUEST["systemBookNumber"],$user);

$_SESSION['data']=NULL;
unset($_GET['m']);
unset($_SESSION['data']);

}
?>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章