<?php
$con=mysqli_connect('localhost','root','root','ren');
mysqli_set_charset($con,'utf8');
error_reporting(E_ALL);//报告所有错误
date_default_timezone_set('PRC'); //设置时区为中国
/** PHPExcel_IOFactory */
require_once './PHPExcel/IOFactory.php';
$target_dir = "excel/";
$target_file = $target_dir . basename($_FILES["file_excel"]["name"]);
$ext=substr($target_file,strripos($target_file,'.'));
$dataSheet=[];
if($ext=='.xlsx'){
//按Excel2007文件格式读取
$reader = PHPExcel_IOFactory::createReader('Excel2007');
$PHPExcel = $reader->load($target_file);
//读取第一个工作表
$sheet = $PHPExcel->getSheet(0);
//获取总行数
$highestRow = $sheet->getHighestRow();
//获取总列数
$highestColumm = $sheet->getHighestColumn();
//读取单元格的数据(从第一行,A列开始先行后列)
for ($row = 5; $row <= $highestRow; $row++){
$a = $PHPExcel->getActiveSheet()->getCell("A".$row)->getValue();
$b = $PHPExcel->getActiveSheet()->getCell("B".$row)->getValue();
$c = $PHPExcel->getActiveSheet()->getCell("C".$row)->getValue();
$d = $PHPExcel->getActiveSheet()->getCell("D".$row)->getValue();
$e = $PHPExcel->getActiveSheet()->getCell("E".$row)->getValue();
//$f = $PHPExcel->getActiveSheet()->getCell("F".$row)->getValue();
$g = $PHPExcel->getActiveSheet()->getCell("G".$row)->getValue();
$h = $PHPExcel->getActiveSheet()->getCell("H".$row)->getValue();
$i = $PHPExcel->getActiveSheet()->getCell("I".$row)->getValue();
$j = $PHPExcel->getActiveSheet()->getCell("J".$row)->getValue();
$k = $PHPExcel->getActiveSheet()->getCell("K".$row)->getValue();
$l = $PHPExcel->getActiveSheet()->getCell("L".$row)->getValue();
$m = $PHPExcel->getActiveSheet()->getCell("M".$row)->getValue();
$n = $PHPExcel->getActiveSheet()->getCell("N".$row)->getValue();
$o = $PHPExcel->getActiveSheet()->getCell("O".$row)->getValue();
$p = $PHPExcel->getActiveSheet()->getCell("P".$row)->getValue();
$q = $PHPExcel->getActiveSheet()->getCell("Q".$row)->getValue();
$r = $PHPExcel->getActiveSheet()->getCell("R".$row)->getValue();
$s = $PHPExcel->getActiveSheet()->getCell("S".$row)->getValue();
$t = $PHPExcel->getActiveSheet()->getCell("T".$row)->getValue();
$u = $PHPExcel->getActiveSheet()->getCell("U".$row)->getValue();
$v = $PHPExcel->getActiveSheet()->getCell("V".$row)->getValue();
$w = $PHPExcel->getActiveSheet()->getCell("W".$row)->getValue();
$x = $PHPExcel->getActiveSheet()->getCell("X".$row)->getValue();
$y = $PHPExcel->getActiveSheet()->getCell("Y".$row)->getValue();
$sql = "INSERT INTO kaoqin_information VALUES ('$a','$b','$c','$d','$e','$g','$h','$i','$j','$k','$l','$m','$n','$o','$p','$q','$r','$s','$t','$u','$v','$w','$x','$y')"; //插入数据库
$result = mysqli_query($con, $sql);
if($result)
{
$sta="ok";
}
else{
$sta="on";
}
}
if($sta=="ok"){
echo '<script>alert("数据导入成功!");</script>';
require './6_kaoqin_information.php';
}
else{
echo "<script>alert('失败!')</script>";
echo mysqli_error($con);
}
}
else{
exit("不能识别{$target_file}.\n");
}
?>