如何用php生成一个大的Excel文件?

我必须自动生成Excel文件,Excel文件包含15.000到50.000行和75列. @H_404_1@它是使用Excel中的连接和公式获得的(68个Excel公式,有IF,IFERROR,COUNTIF …).

@H_404_1@所以我选择了PHPExcel库,但是我必须在1h15到1h30之间等待,我已经减少了循环次数.在阅读了大量文档后,我注意到这是PHPExcel的问题.

@H_404_1@如果我考虑创建一个包含从我的数据库中检索的所有Excel公式和数据的PHP数组的可能性,这个方法需要很长时间,而且我不确定它是否会起作用.

@H_404_1@所以我问你,还有另外一种方法吗?一种生成Excel工作簿类型的方法,该类型包含大量数据(包含1或2百万个单元格)和公式(在15分钟内).

<?PHP       
require_once dirname(__FILE__) . '/Classes/PHPExcel.PHP';
require_once dirname(__FILE__) .  '/Classes/PHPExcel/IOFactory.PHP';

$path = "Lirefichierexcel/Trame.xlsx";

$objPHPExcel = new PHPExcel(); 
$sheet = $objPHPExcel-> getActiveSheet();

$rowCount =5;

$worksheetTitle = $sheet->getTitle();
$highestRow = $sheet->getHighestRow(); // e.g. 10
$highestColumn = $sheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;

$rowCount=5;

   $projet=$_REQUEST['projet'];
     try {
       //Etablir la connexxion
       include 'Proprietes.PHP';

       $connexion = new PDO("$driver:host=$host;dbname=$dbase",$user,$password);

       //Préparer la requête
       $requetesql="select * from $projet as a left join feuille_de_prix as b 
       on b.Liasse = a.Liasse and b.Item = a.Item order by 1";
        $requetePreparee= $connexion->prepare($requetesql);

       //Exécuter la requête
     $resultat = $requetePreparee->execute();

     //Tester le résultat
     if(! $resultat) die("<p>La lecture a échoué</>\n");
    else {

   echo "<h1>Jointure entre le $projet et la feuille de prix </h1>";

       while($ligne=$requetePreparee->fetch()){

    $sheet->SetCellValue('F'.$rowCount,$ligne[4])
    ->SetCellValue('F'.$rowCount,$ligne[4])    

   $rowCount++;

    } 

       $worksheetTitle = $sheet->getTitle();
$highestRow = $sheet->getHighestRow(); // e.g. 10
$highestColumn = $sheet->getHighestColumn(); // e.g 'F'
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
$nrColumns = ord($highestColumn) - 64;

      for ($row = 5; $row <= $highestRow; ++ $row) {
    $row1=$row+1;
    $rowm1=$row-1;

       //AA4
    $sheet->setCellValue(
            'AA' . $row,'=..............')

//AB4
        ->setCellValue(
            'AB' . $row,'=..............')

}

}

echo date('H:i:s')," Write to Excel2007 format",PHP_EOL;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save(str_replace('.PHP','.xlsx',__FILE__));
echo date('H:i:s')," File written to ",str_replace('.PHP',__FILE__),PHP_EOL;
// Echo memory peak usage
echo date('H:i:s')," Peak memory usage: ",(memory_get_peak_usage(true) / 1024 / 1024)," MB",PHP_EOL;

// Echo done
echo date('H:i:s')," Done writing file",PHP_EOL;

     $connexion=null;

   }catch (PDOException $e) {
     print "Erreur !: " . $e->getMessage() . "<br/>";
     die();
    }

    ?>
使用BoxSpout.
@H_404_1@It is a PHP library to read and write CSV and XLSX
files,in a fast and scalable way. Contrary to other file readers or
writers,it is capable of processing very large files while keeping
the memory usage really low (less than 10MB). Here are a few numbers regarding the performance of Spout.

@H_404_1@https://github.com/box/spout

相关文章

Hessian开源的远程通讯,采用二进制 RPC的协议,基于 HTTP 传输。可以实现PHP调用Java,Python,C#等多语...
初识Mongodb的一些总结,在Mac Os X下真实搭建mongodb环境,以及分享个Mongodb管理工具,学习期间一些总结...
边看边操作,这样才能记得牢,实践是检验真理的唯一标准.光看不练假把式,光练不看傻把式,边看边练真把式....
在php中,结果输出一共有两种方式:echo和print,下面将对两种方式做一个比较。 echo与print的区别: (...
在安装好wampServer后,一直没有使用phpMyAdmin,今天用了一下,phpMyAdmin显示错误:The mbstring exte...
变量是用于存储数据的容器,与代数相似,可以给变量赋予某个确定的值(例如:$x=3)或者是赋予其它的变...