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();
d
a
t
e
=
date=
date=M->date();
foreach($array as $t){
$arr=array();
$arr["number"]=$number;
a r r [ " c u s t o m e r " ] = a d d s l a s h e s ( arr["customer"]=addslashes( arr["customer"]=addslashes(t[0]); a r r [ " s u p p l i e r " ] = a d d s l a s h e s ( arr["supplier"]=addslashes( arr["supplier"]=addslashes(t[1]); a r r [ " o r d e r N u m b e r " ] = " " ; arr["orderNumber"]=""; arr["orderNumber"]="";arr[“materialCode”]=addslashes(""); a r r [ " c a r t o n N u m b e r " ] = " " ; arr["cartonNumber"]=""; arr["cartonNumber"]="";arr[“PONumber”]=addslashes( t [ 3 ] ) ; t[3]); t[3]);arr[“productName”]=addslashes(""); a r r [ " p r o d u c t C o d e " ] = " " ; arr["productCode"]=""; arr["productCode"]="";arr[“SKU”]=addslashes( t [ 4 ] ) ; t[4]); t[4]);arr[“SKUName”]=""; a r r [ " U P C " ] = a d d s l a s h e s ( arr["UPC"]=addslashes( arr["UPC"]=addslashes(t[9]); a r r [ " f a c t o r y " ] = a d d s l a s h e s ( arr["factory"]=addslashes( arr["factory"]=addslashes(t[2]); a r r [ " d e s c r i p t i o n " ] = a d d s l a s h e s ( arr["description"]=addslashes( arr["description"]=addslashes(t[11]); a r r [ " s t y l e " ] = a d d s l a s h e s ( arr["style"]=addslashes( arr["style"]=addslashes(t[5]); a r r [ " s t y l e N a m e " ] = a d d s l a s h e s ( arr["styleName"]=addslashes( arr["styleName"]=addslashes(t[10]); a r r [ " C O O " ] = a d d s l a s h e s ( arr["COO"]=addslashes( arr["COO"]=addslashes(t[17]); a r r [ " l o t " ] = a d d s l a s h e s ( arr["lot"]=addslashes( arr["lot"]=addslashes(t[14]); a r r [ " c o l o r " ] = a d d s l a s h e s ( arr["color"]=addslashes( arr["color"]=addslashes(t[6]); a r r [ " c o l o r C o d e " ] = a d d s l a s h e s ( arr["colorCode"]=addslashes( arr["colorCode"]=addslashes(t[7]); a r r [ " s i z e " ] = a d d s l a s h e s ( arr["size"]=addslashes( arr["size"]=addslashes(t[8]); a r r [ " o t h e r s " ] = " " ; arr["others"]=""; arr["others"]="";arr[“length”]=""; a r r [ " w i d t h " ] = " " ; arr["width"]=""; arr["width"]="";arr[“height”]=""; a r r [ " w e i g h t G " ] = " " ; arr["weightG"]=""; arr["weightG"]="";arr[“weightN”]=""; a r r [ " v o l u m e " ] = " " ; arr["volume"]=""; arr["volume"]="";arr[“price”]= t [ 15 ] ; t[15]; t[15];arr[“currency”]=addslashes( t [ 16 ] ) ; t[16]); t[16]);arr[“qtyPerCarton”]=""; a r r [ " q t y " ] = arr["qty"]= arr["qty"]=t[12]; a r r [ " r e c e i v e d Q t y " ] = " " ; arr["receivedQty"]=""; arr["receivedQty"]="";arr[“receivedDate”]=addslashes( t [ 13 ] ) ; t[13]); t[13]);arr[“created”]= d a t e ; 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.从第二行开始读
v
a
l
u
e
=
value=
value=obj->read($_FILES[‘fileName’][‘tmp_name’]);
S
E
S
S
I
O
N
[
′
d
a
t
a
′
]
=
s
e
r
i
a
l
i
z
e
(
_SESSION['data'] = serialize(
SESSION[′data′]=serialize(value);
t
i
t
l
e
=
"
<
t
h
>
行
<
/
t
h
>
"
;
f
o
r
(
title="<th>行</th>"; for(
title="<th>行</th>";for(t=0;
t
<
31
;
t<31;
t<31;t++){
if($t<26){
t
i
t
l
e
.
=
"
<
t
h
>
"
.
c
h
r
(
65
+
title.="<th>".chr(65+
title.="<th>".chr(65+t)."";
}else{
t
i
t
l
e
.
=
"
<
t
h
>
A
"
.
c
h
r
(
title.="<th>A".chr(
title.="<th>A".chr(t+39)."";
}//if
}//for
echo ‘
foreach($value AS k = > k=> k=>v){
echo ‘’;
}//foreach
echo ‘’;
}//foreach
echo ‘
’. v a l u e [ 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']);
}
?>