zoukankan      html  css  js  c++  java
  • phpexcel导入excel处理大数据

    先下载对应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;
        }
    }                      
  • 相关阅读:
    C#系列之聊聊.Net Core的InMemoryCache
    函数式编程之-重新认识泛型(2)
    函数式编程之-重新认识泛型(1)
    ThreadLocal源码深度剖析
    使用ThreadLocal
    详解Redis中两种持久化机制RDB和AOF(面试常问,工作常用)
    Cassandra
    一致性HASH算法在分布式应用场景使用
    柔性分布式事务关于异步解决方案MQ版
    AtomicReference
  • 原文地址:https://www.cnblogs.com/sztx/p/9499771.html
Copyright © 2011-2022 走看看