我有以下代码应该使用 PHPExcel 为我生成一个 Excel 工作表,但问题是它需要永远运行。我也有一些 Doctrine PHP 代码。Doctrine 代码连接到数据库并选择我想用来填充 Excel 文件的数据。下面是代码。请有人告诉我出了什么问题
/** Error reporting */
error_reporting(E_ALL);
if (!isset($_SESSION)) {
// session_name("mediapp123456");
session_start();
}
require_once ('bootstrap.php');
$conn = Doctrine_Manager::connection ( DSN );
$q = Doctrine_Query::create()
->select('u.*')
->from('UserQuestionnaire u')
->orderBy('u.id DESC');
$row = $q->execute();
date_default_timezone_set('Europe/London');
/** PHPExcel */
require_once 'excelreports/Classes/PHPExcel.php';
// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPExcel->getProperties()->setCreator("Ifeanyi Agu")
->setLastModifiedBy("Ifeanyi Agu")
->setTitle("QUSER")
->setSubject("QUSER")
->setDescription("QUser Generated Document")
->setKeywords("xml")
->setCategory("Test result file");
// Add some data
echo date('H:i:s') . " Add some data\n";
$objPHPExcel->getActiveSheet()->mergeCells('B2:F2')
->mergeCells('G2:K2')
->setCellValue('I2', 'FEATURES')
->mergeCells('L2:AI2')
->setCellValue('W2', 'EXPECTATION')
->mergeCells('AJ2:BG2')
->setCellValue('AU2', 'PERCEPTION')
->mergeCells('L3:03')
->setCellValue('M', 'Tangible');
$objPHPExcel->getActiveSheet()->setCellValue('A4', 'No')
->setCellValue('B4', 'School')
->setCellValue('C4', 'Dept')
->setCellValue('D4', 'Status')
->setCellValue('E4', 'Browse')
->setCellValue('F4', 'How Long')
->setCellValue('G4', 'Tangibility')
->setCellValue('H4', 'Reliability')
->setCellValue('I4', 'Assurance')
->setCellValue('J4', 'Responsive')
->setCellValue('K4', 'Empathy')
->setCellValue('L4', 'E1')
->setCellValue('M4', 'E2')
->setCellValue('N4', 'E3')
->setCellValue('O4', 'E4')
->setCellValue('P4', 'E5')
->setCellValue('Q4', 'E6')
->setCellValue('R4', 'E7')
->setCellValue('S4', 'E8');
$i=4;
foreach($row as $rows)
{
$i++;
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, ($i-4))
->setCellValue('B'.$i, $rows->schoolname)
->setCellValue('C'.$i, $rows->department)
->setCellValue('D'.$i, $rows->status)
->setCellValue('E'.$i, $rows->doyoubrowse)
->setCellValue('F'.$i, $rows->browselength);
}
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', FILE));
// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
?>