<?php
header("Content-Type:text/html;charset=utf-8");
include_once('PHPExcel.php');
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
//date_default_timezone_set('Europe/London');
$PHPExcel=new PHPExcel();
$filename = 'phone.xls';
$exts = substr($filename,(strrpos($filename,".")+1));
if($exts == 'xls'){
include_once('PHPExcel/Reader/Excel5.php');
$PHPReader=new \PHPExcel_Reader_Excel5();
}else if($exts == 'xlsx'){
include_once('PHPExcel/Reader/Excel2007.php');
$PHPReader=new \PHPExcel_Reader_Excel2007();
}
$PHPExcel=$PHPReader->load($filename);
$currentSheet=$PHPExcel->getSheet(0);
$allColumn=$currentSheet->getHighestColumn();
$allRow=$currentSheet->getHighestRow();
for($currentRow=1;$currentRow<=$allRow;$currentRow++){
for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
$address=$currentColumn.$currentRow;
$data[$currentRow][$currentColumn]=$currentSheet->getCell($address)->getValue();
}
}
$json = json_encode($data);
try{
$dsn='mysql:host=localhost;dbname=kaoqing';
$username='root';
$passwd='root';
$pdo=new PDO($dsn,$username,$passwd);
$pdo->query("SET NAMES utf8");
}catch(PDOException $e){
echo $e->getMessage();
}
$f = '';
foreach ($data as $item){
$arr=[];
$a=!empty($item['F'])?$item['F']:$f;
$arr['depart']=$item['A'];
$arr['name']=$item['B'];
$arr['kaonumber']=$item['C'];
$arr['time']=$item['D'];
$arr['jinumber']=$item['E'];
$arr['biannumber']=$f;
$arr['type']=$item['G'];
$arr['carnumber']=$item['H'];
$arr['yuanyin'] = $item['I'];
$reslut = $pdo->exec($sql);
$sql = sprintf('INSERT INTO `%s` (`%s`) VALUES ("%s")','kaoqing',join( '`,`',array_keys($arr)),join('","',$arr));
$reslut = $pdo->exec($sql);
}
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!