excel導入

一:引入導入得內部文件以及數據導入php

<?php
include("PHPExcel-1.8/Classes/PHPExcel/IOFactory.php");
$exec=PHPExcel_IOFactory::load("01simple.xls");
$ex=$exec->getSheet(0);
$row=$ex->getHighestDataRow();
for($i=2;$i<=$row;$i++){
$data=$ex->getCell("A".$i)->getValue();
$data1=$ex->getCell("B".$i)->getValue();
$data2=$ex->getCell("C".$i)->getValue();
$data3=$ex->getCell("D".$i)->getValue();
$pdo=new PDO("mysql:host=127.0.0.1;dbname=testz","root","root");
$pdo->exec("insert into class(id,claname,num,clas)values('$data','$data1','$data2','$data3')");

//$sql="insert into class(id,claname,num,clas)values('$data','$data1','$data2','$data3')";
//echo $sql;

}
$res=$pdo->query("select*from class")->fetchAll();
?>

二:HTLML數據展現部分html

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<table>
<tr>
<td>id</td>
<td>num</td>
<td>cont</td>
<td>tel</td>
<td>操做</td>
</tr>
<?php foreach($res as $k=>$v) {?>
<tr>
<td><?php echo $v['id'] ?></td>
<td><?php echo $v['claname'] ?></td>
<td><?php echo $v['num'] ?></td>
<td><?php echo $v['clas'] ?></td>
<td><a href="xiu.php?id=<?php echo $v['id'] ?>&name=<?php echo $v['claname'] ?>&num=<?php echo $v['num'] ?>&clas=<?php echo $v['clas'] ?> ">修改</a></td>
</tr>
<?php }?>
</table>
</body>
</html>
相關文章
相關標籤/搜索