public function excel_runimport(){
import("Org.Util.PHPExcel");
$PHPExcel=new \PHPExcel();
import("Org.Util.PHPExcel.Reader.Excel5");
if (! empty ( $_FILES ['file_stu'] ['name'] )){
$tmp_file = $_FILES ['file_stu'] ['tmp_name'];
$file_types = explode ( ".", $_FILES ['file_stu'] ['name'] );
$file_type = $file_types [count ( $file_types ) - 1];
/*判别是不是.xls文件,判别是不是excel文件*/
if (strtolower ( $file_type ) != "xls"){
$this->error ( '不是Excel文件,重新上传',U('excel_import'),0);
}
/*设置上传路径*/
$savePath = './Public/excel/';
/*以时间来命名上传的文件*/
$str = time ( 'Ymdhis' );
$file_name = $str . "." . $file_type;
if (! copy ( $tmp_file, $savePath . $file_name )){
$this->error ('上传失败',U('excel_import'),0);
}
$res = $this->read ( $savePath . $file_name );
if (!$res){
$this->error ('数据处理失败失败',U('excel_import'),0);
}
//spl_autoload_register ( array ('Think', 'autoload' ) );
foreach ( $res as $k => $v ){
if ($k != 1){
$data ['cateid'] = $v[0];
$data ['bianhao'] = $v[1];
$data ['pinming'] = $v[2];
$data ['bieming'] = $v[3];
$data ['guige'] = $v[4];
$data ['pinpai'] = $v[5];
$data ['jiage'] = $v[6];
$data ['cas'] = $v[7];
$data ['chucun'] = $v[8];
$data ['yingwenming'] = $v[9];
$data ['pihao'] = $v[10];
$result = M ('product')->add ($data);
if (!$result){
$this->error ('导入数据库失败',U('excel_import'),0);
}
}
}
$this->success ('导入数据库成功',U('excel_import'),1);
}
}
import("Org.Util.PHPExcel");
$PHPExcel=new \PHPExcel();
import("Org.Util.PHPExcel.Reader.Excel5");
if (! empty ( $_FILES ['file_stu'] ['name'] )){
$tmp_file = $_FILES ['file_stu'] ['tmp_name'];
$file_types = explode ( ".", $_FILES ['file_stu'] ['name'] );
$file_type = $file_types [count ( $file_types ) - 1];
/*判别是不是.xls文件,判别是不是excel文件*/
if (strtolower ( $file_type ) != "xls"){
$this->error ( '不是Excel文件,重新上传',U('excel_import'),0);
}
/*设置上传路径*/
$savePath = './Public/excel/';
/*以时间来命名上传的文件*/
$str = time ( 'Ymdhis' );
$file_name = $str . "." . $file_type;
if (! copy ( $tmp_file, $savePath . $file_name )){
$this->error ('上传失败',U('excel_import'),0);
}
$res = $this->read ( $savePath . $file_name );
if (!$res){
$this->error ('数据处理失败失败',U('excel_import'),0);
}
//spl_autoload_register ( array ('Think', 'autoload' ) );
foreach ( $res as $k => $v ){
if ($k != 1){
$data ['cateid'] = $v[0];
$data ['bianhao'] = $v[1];
$data ['pinming'] = $v[2];
$data ['bieming'] = $v[3];
$data ['guige'] = $v[4];
$data ['pinpai'] = $v[5];
$data ['jiage'] = $v[6];
$data ['cas'] = $v[7];
$data ['chucun'] = $v[8];
$data ['yingwenming'] = $v[9];
$data ['pihao'] = $v[10];
$result = M ('product')->add ($data);
if (!$result){
$this->error ('导入数据库失败',U('excel_import'),0);
}
}
}
$this->success ('导入数据库成功',U('excel_import'),1);
}
}