0

我想将一些文件 php 导出到 XLS 文件使用类 PHPEXcel,我以前没有使用过这个。

我的浏览器上的通知: “致命错误:第 1124 行 C:\AppServ\www\kjjp2\Classes\PHPExcel\Cell.php 中允许的内存大小为 25165824 字节已用尽(试图分配 1056 字节)”

代码:

    <?php
    include "config/koneksi.php";

    error_reporting(E_ALL);
    require_once 'Classes/PHPExcel.php';
    // Create new PHPExcel object
    $objPHPExcel = new PHPExcel();

    $query = "SELECT * FROM `tabeldata`";
    $hasil = mysql_query($query);

    // Set properties
    $objPHPExcel->getProperties()->setCreator("Erik")
    ->setLastModifiedBy("Erik")
    ->setTitle("Office 2007 XLSX ")
    ->setSubject("Office 2007 XLSX ")
    ->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
   ->setCategory("Test result file");

    // Add some data
    $objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A1', 'Jenis Report')
    ->setCellValue('B1', 'Pembayaran')
    ->setCellValue('C1', 'No')
    ->setCellValue('D1', 'Cabang')
     //and some files


    ->setCellValue('AG1', 'Surveyor');

    $rowNya = 3;
    $no = 0;
    while($row=mysql_fetch_array($hasil)){
    $no = $no +1;
    $objPHPExcel->setActiveSheetIndex(0)

    ->setCellValue("A$rowNya", $row['jenReport'])
    ->setCellValue("B$rowNya", $row['pembayaran'])
     ->setCellValue("C$rowNya", $row['no'])
     ->setCellValue("D$rowNya", $row['cabang'])
    ->setCellValue("E$rowNya", $row['namaSales'])
    ->setCellValue("F$rowNya", $row['jenLaporan'])
          //and some files

    ->setCellValue("AG$rowNya", $row['surveyor']);


    $rowNya = $rowNya + 1;
    }

    // Rename sheet
    $objPHPExcel->getActiveSheet()->setTitle('Simple');

    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $objPHPExcel->setActiveSheetIndex(0);

    // Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="database.xls"');
    header('Cache-Control: max-age=0');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
    exit;
    ?>
4

2 回答 2

0

您正在用完可供 PHP 使用的 RAM。您可以在 php.ini 中设置 PHP 将使用多少 RAM。您目前将此限制设置为 24MB,这非常低。尝试增加它。

ini_set('memory_limit', '256M');
于 2013-06-17T06:03:09.603 回答
0

PHPExcel 以内存消耗着称。该网站讨论了一些解决方法,请参阅http://phpexcel.codeplex.com/discussions/242712?ProjectName=phpexcel

您还可以考虑使用另一个库,例如旧的 Spreadsheet_Excel_Writer 库(也有其缺点) http://pear.php.net/package/Spreadsheet_Excel_Writer/redirected

于 2013-06-17T06:25:17.217 回答