先下载对应phpexcel 的包就行了https://github.com/phpoffice/phpexcel
下载完成 把那个classes 这个文件夹里面的 文件跟文件夹拿出来就好了。
直接写到phpexcel 这个文件里面的。调用很简单。引入phpexcel 这个类传递对应的excel 文件的路径就好了
现在上传到指定的目录,然后加载上传的excel文件读取这里读取是的时候不转换数组了。注意:是sheet可以多个读取,php上传值要设置大,上传超时要设置长。
header('content-type: text/html; charset=utf-8'); //设置页面编码
require_once 'phpexcel.class.php'; //引入文件
require_once 'phpexcel/iofactory.php'; //引入文件
require_once 'phpexcel/reader/excel2007.php'; //引入文件
$uploadfile = $_files['select_file']['tmp_name']; //获取上传文件
$auid = $_session['auid'];
$date = date('ymd');
$rand = rand(1,9999);
$_month=str_replace('-','',$date);
$file_name = str_pad($auid, 4, 0, str_pad_left).$date.str_pad($rand, 4, 0, str_pad_left).'.xlsx';
$path_file = '../data/upload/file/'.$file_name; //上传文件目录指定
move_uploaded_file($uploadfile, $path_file); //文件上传
$inputfiletype = phpexcel_iofactory::identify($path_file);
$objreader = phpexcel_iofactory::createreader($inputfiletype);
$objreader->setreaddataonly(true);//只需要添加这个方法实现表格数据格式转换
$objphpexcel = $objreader->load($path_file);
$sheet_read_arr = array();
$sheet_read_arr["表1"] = array("b","c");
$sheet_read_arr["表2"] = array("b","c");
$sheet_read_arr["表3"] = array("b","c");
$list_aray=array();
foreach ($sheet_read_arr as $key => $val){
$currentsheet = $objphpexcel->getsheetbyname($key);
$row_num = $currentsheet->gethighestrow();
for ($i = 6; $i <= $row_num; $i++){
$cell_values = array();
foreach ($val as $cell_val){
$address = $cell_val . $i;// 单元格坐标
$cell_values[] = $currentsheet->getcell($address)->getformattedvalue();
}
$list_aray[]=$cell_values;
}
}
以上这篇phpexcel导入excel处理大数据(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持硕编程。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!