跟导出相对应的,同一个数据表,也是将phpexcel类放在class目录下,将Excel表格中的内容读取出来放到数据库中
<?php
error_reporting(E_ALL);
set_time_limit(0);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<?php
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . 'class/');
/** PHPExcel_IOFactory */
include 'class/PHPExcel/IOFactory.php';
$inputFileName = 'class/01simple.xls';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
mysql_connect('localhost','root','root');
mysql_select_db('test');
mysql_query('set names utf8');
var_dump($sheetData);
foreach ($sheetData as $key=>$val) {
$sql = "insert into `user` (id,username,password) values({$val['A']}, '{$val['B']}', '{$val['C']}')";
mysql_query($sql);
}
mysql_close();
?>
<body>
</html>