gpt4 book ai didi

PHPExcel 内存问题 - 还有更多想法吗?

转载 作者:行者123 更新时间:2023-12-03 19:08:00 24 4
gpt4 key购买 nike

我正在尝试使用 Zend Framework 和 PHPExcel 编写 Excel2007 文件。我知道我可以增加 PHP 内存限制.. 但没有其他办法吗?

到目前为止,这是我的代码,它适用于 5000 行和 77 列,但我需要 12000 行:-)内存设置为 128MB

    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_sqlite;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod);

$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$phpExcel = new PHPExcel();

// set headers
$select = $db->select();
$select->from('IMPORT')->limit(1);
$data = $select->query()->fetchAll();
$columns = array_keys($data[0]);
$phpExcel->setActiveSheetIndex(0);
$colCNT = 1;

foreach ($columns as $column) {
$letter = Nc_Utils::getNameFromNumber($colCNT);
$phpExcel->getActiveSheet()->SetCellValue($letter . '1', $column);
$colCNT++;
}

unset($select);
unset($data);

$sql = 'SELECT * FROM IMPORT LIMIT 7000';
$stmt = $db->query($sql);

$rowCNT = 2;
while($rows = $stmt->fetch()){
$phpExcel->getActiveSheet()->fromArray($rows, null, 'A'.$rowCNT);
$rowCNT++;
}

unset($rowCNT);
unset($select);
unset($db);

// MEMORY USAGE = 4 MB!

$phpExcelWrite = new PHPExcel_Writer_Excel2007($phpExcel);
$phpExcelWrite->setUseDiskCaching(true);
$phpExcelWrite->save(str_replace('.php', '.xls', __FILE__));

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 13878925 bytes) in /Applications/MAMP/htdocs/phpexcel/library/PHPExcel/Shared/XMLWriter.php on line 102

最佳答案

PHPExcel 网站 has a discussion关于减少内存消耗的可能方法:

关于PHPExcel 内存问题 - 还有更多想法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12251459/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com