doulou1989 2013-06-17 04:56
浏览 29
已采纳

导出文件php到xls使用类PHPExcel

I want to export some file php to XLS file use class PHPEXcel, I don't used this before.

notif on my browser: "Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 1056 bytes) in C:\AppServ\www\kjjp2\Classes\PHPExcel\Cell.php on line 1124"

code:

    <?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;
    ?>
  • 写回答

2条回答 默认 最新

  • dre75230 2013-06-17 06:03
    关注

    You are running out of RAM that can be used by PHP. You can set how much RAM that PHP will use in php.ini. You currently have this limit set to 24MB, which is pretty low. Try increasing it.

    ini_set('memory_limit', '256M');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码