Blank page displayed if output is more than 100 rows.

Topics: Developer Forum
Dec 10, 2010 at 9:51 AM

Hi all,

I am getting a blank page when I try to write more than 100 rows into a .xls file. 96 rows is fine and works good. Here's my script.


$data = getProducts();
//  # filename for download
  $filename = "Products .xls";
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set properties
        ->setTitle("Office 2007 XLSX Document")
        ->setSubject("Office 2007 XLSX Document")
        ->setDescription("Document for Office 2007 XLSX, generated using PHP classes.")
        ->setKeywords("office 2007 openxml php")
        ->setCategory("Product Setup Data");

//Assuming that we will never cross more than 26 columns.
$cell_name = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$total_cols = count($data[0]);
// Add data
$i = 1;
foreach($data as $row) {
 $j = 0;
 foreach($row as $val){
            ->setCellValue($cell_name[$j].$i, $val);
// Rename sheet
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

No errors are reported in either PHP or Apache.  Any suggestions ?? or any idea what  the problem is?



Dec 10, 2010 at 9:28 PM
Edited Dec 10, 2010 at 9:34 PM

Obvious possibilities ar timeout or running into memory limits.

Note that you don't need the $cell_name array if you use the built in methods of PHPExcel_Cell::stringFromColumnIndex() to convert 0 to 'A', 1 to 'B', 26 to 'AA', etc; or setCellValueByColumnAndRow() rather than setCellValue()