PHP export large amount of data to excel sheet

/**
     * @creator Jimmy
     * @data 2016/8/22
     * @desc data is exported to excel (csv file)
     * @param $filename The name of the exported csv file is date("Y year m month j day").'-PB institution list.csv'
     * @param array $tileArray all column names
     * @param array $dataArray all column data
     */
    public static function exportToExcel($filename, $tileArray=[], $dataArray=[]){
        ini_set('memory_limit','512M');
        ini_set('max_execution_time',0);
        ob_end_clean();
        ob_start();
        header("Content-Type: text/csv");
        header("Content-Disposition:filename=".$filename);
        $fp=fopen('php://output','w');
        fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));
//        $fp=fopen('D://hello.csv','w');
        fputcsv($fp,$tileArray);
        $index = 0;
        foreach ($dataArray as $item) {
            if($index==1000){
                $index=0;
                ob_flush();
                flush();
            }
            $index++;
            fputcsv($fp,$item);
        }

        ob_flush();
        flush();
        ob_end_clean();
    }

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325948027&siteId=291194637