跳至
[1]
[全屏预览]
load("mb.xlsx"); // 载入excel文件
$sheet = $PHPExcel->getSheet(0); // 读取第一個工作表
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumm = $sheet->getHighestColumn(); // 取得总列数
//1.导入配置文件
require("conf/dbconfig.php");
//2.连接MySQL、并选择数据库
$link = @mysql_connect(HOST, USER, PASS) or die("数据库连接失败!");
mysql_select_db(DBNAME, $link);
//循环读取excel文件,读取一条,插入一条
for ($j = 2; $j <= $highestRow; $j++) {
$name = $PHPExcel->getActiveSheet()->getCell("A" . $j)->getValue();//获取A列的值
$telephone = $PHPExcel->getActiveSheet()->getCell("B" . $j)->getValue();//获取B列的值
$fenzu = $PHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();//获取C列的值
$school = $PHPExcel->getActiveSheet()->getCell("D" . $j)->getValue();//获取D列的值
$banji = $PHPExcel->getActiveSheet()->getCell("E" . $j)->getValue();//获取E列的值
$sql = "INSERT INTO `drtable`(`id`, `name`, `telephone`, `fenzu`, `school`, `banji`) VALUES (null,'{$name}','{$telephone}','{$fenzu}','{$school}','{$banji}')";
mysql_query($sql, $link);
echo $sql;
}
?>