qq_慕瓜0338836
itliujia
qq_闹腾_3
我也遇到了这个情况,请问你是怎么解决的?
一颗低调的大白菜
从心开始0
有源文件的,你运行一下,看
慕粉0450349489
思路如下:
遍历文件夹,获取文件夹中所有excel表格的名称;
引入PHPExcel,进行缓存设置,并且实例化PHPExcel;
foreah遍历文件夹中的名称,然后中间是你要实现的逻辑代码;
实际上还是重复读取一个excel文件的操作。
fighting_wjz
根据老师的课程,然后就是mysql操作了。。。。
易园天下3192653
$dir=dirname(__FILE__);//找到当前脚本所在路径
wenzki
qq_小寒挽歌_0
wuzzxx
改为另外一个方法咯。
import.php
session_start();
header("Content-type:text/html;charset:utf-8");
//全局变量
$succ_result=0;
$error_result=0;
$file=$_FILES['filename'];
$max_size="2000000"; //最大文件限制(单位:byte)
$fname=$file['name'];
$ftype=strtolower(substr(strrchr($fname,'.'),1));//文件格式
$uploadfile=$file['tmp_name'];
if($_SERVER['REQUEST_METHOD']=='POST'){
if(is_uploaded_file($uploadfile)){
if($file['size']>$max_size){
echo "Import file is too large";
exit;
}
if($ftype!='xls'){
echo "Import file type is error";
exit;
}
}else{
echo "The file is not empty!";
exit;
}
}
$dir=dirname(__FILE__);//查找当前脚本所在路径
require $dir."/db.php";//引入mysql操作类文件
$db=new db($link);//实例化db类 连接数据库
require_once $dir."/PHPExcel/PHPExcel.php";//引入PHPExcel
require_once $dir."/PHPExcel/PHPExcel/IOFactory.php";
require_once $dir."/PHPExcel/PHPExcel/Reader/Excel5.php";
//stackoverflow 方法
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($uploadfile);
$objWorksheet = $objPHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$rows = array();for ($row = 2; $row <= $highestRow; ++$row) {
for ($col = 0; $col <= $highestColumnIndex; ++$col) {
$rows[$col] = mysql_real_escape_string($objWorksheet->getCellByColumnAndRow($col, $row)->getValue());
}
//print_r($rows);
mysql_query("set names utf8");
mysql_query("INSERT INTO `user`(username,class,score)
VALUES ('$rows[0]',$rows[1],$rows[2])")or die("执行错误");
$insert_num=mysql_affected_rows();
if($insert_num>0){
$succ_result+=1;
}else{
$error_result+=1;
}
}echo "插入成功".$succ_result."条数据!!!<br>"; echo "插入失败".$error_result."条数据!!!";
墨西哥鸡味卷
我也想有呀..... 耐着性子看看吧 多看点英文手册是很有必要也很有好处的
利剑Jean
呃,能有点更具体的提示么 贴出错误也行