• php解决导出大数据execl问题


    描述:在实际工作中,有时候我们需要导出大量数据到execl里面,可以参考分页方式导出,将每一页的数据放进php输出流里面 代码如下

    <?php
        ini_set('memory_limit', '2048M'); 
        header('Content-Description: File Transfer');
        header('Content-Type: application/vnd.ms-excel');
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        $filename ="111.xlsx";
        header("Content-Disposition:filename={$filename}");
        $fp = fopen("php://output",'a');
        $title = ["id", "name", "age","aa","bb"];
    
        $str = implode("\t",$title)."\n";
        fwrite($fp,$str,strlen($str));
        $bigData=[];
        for($i=0;$i<1000000;$i++){
            $tmp=[];
            $tmp["id"]=1;
            $tmp["name"]="lisi";
            $tmp["age"]=20;
            $tmp["aa"] = 20;
            $tmp["bb"] = 20;
    
            array_push($bigData,$tmp);
        }
       $result = array_chunk($bigData,5);
        for($i=0;$i<count($result);$i++){
            $data = $result[$i];
            for($j=0;$j<count($data);$j++){
               $show=[];
               $id = $data[$j]["id"];
               $name = $data[$j]["name"];
               $age = $data[$j]["age"];
               $aa = $data[$j]["aa"];
               $bb = $data[$j]["bb"];
    
                array_push($show,$id);
                array_push($show, $name);
                array_push($show, $age);
                array_push($show, $aa);
                array_push($show, $bb);
               $strshow = implode("\t",$show)."\n";
               fwrite($fp,$strshow);
            }
            file_put_contents("./1.txt",$i,FILE_APPEND);
            ob_flush();
            flush();
        }
    
        fclose($fp);
        exit;
    
    ?>
    

      

  • 相关阅读:
    关于JAVA的线程问题
    Java 对JTextField添加回车响应
    Failed to install *.apk on device 'emulator-5554': timeout .
    静态属性
    类与对象的实例属性

    面向对象2
    面向对象设计
    re模块,主要用来查询
    xml对标签操作,
  • 原文地址:https://www.cnblogs.com/zh718594493/p/15767861.html
Copyright © 2020-2023  润新知