dongwo2222 2014-02-09 05:04
浏览 76
已采纳

致命错误:允许的内存大小为xxx字节耗尽Php excel

I have made a script and i am getting the following error. If have upgrade the memory size to 7g still the error. So i tried to append 10000 records and save it and go for the next 10000 to solve it, works, but still getting the error.

Is there any way to flush the workbook or other methods?

Thnx!

The awnser:

PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);   
$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_discISAM;
$cacheSettings = array( 
    'dir' => '/home/domains/xxxx.nl/public_html/xxxxx'
);



require_once 'PHPExcel.php';
require_once 'PHPExcel/Writer/Excel2007.php';
require_once 'PHPExcel/IOFactory.php';



$counter = $result->num_rows;//159920
$spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();


//header
$worksheet->setCellValueExplicit('A' . 1, 'Filename', PHPExcel_Cell_DataType::TYPE_STRING);
etc
etc

$rownr = 2;
$counterN = 0;
while ($row = mysqli_fetch_assoc($result)) {  
    $worksheet->setCellValueExplicit('A' . $rownr, utf8_encode($row['filename']), PHPExcel_Cell_DataType::TYPE_STRING);
    etc
    etc

    if( $counterN == 10000 ){

        $objWriter = new PHPExcel_Writer_Excel2007($spreadsheet);
        $objWriter->save('test.xlsx');

        $objPHPExcel = PHPExcel_IOFactory::load("test.xlsx");
        $objPHPExcel->setActiveSheetIndex(0);
        $row = $objPHPExcel->getActiveSheet()->getHighestRow()+1;
        $counterN = 0;
    }
    $counterN++;

}

$objWriter = new PHPExcel_Writer_Excel2007($spreadsheet);
$objWriter->save('test.xlsx');
  • 写回答

1条回答 默认 最新

  • doushan2811 2014-02-09 11:22
    关注

    If you don't have enough memory to handle a large number of cells, then the recommended method of reducing memory usage is to use cell caching, as described in section 4.2.1. of the developer documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么