phpexcel导入excel处理大数据(实例讲解)

(编辑:jimmy 日期: 2024/10/3 浏览:2)

先下载对应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处理大数据(实例讲解)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。