repeat rows not working in excel 2007

Topics: Developer Forum
Jan 5, 2010 at 3:56 PM

Hi All

I have a very simple report that is being generated from data and all the cell formatting is fine. The problem I have is that the column headings will not repeat for each new page of the report.

I am using the following code with the repeat rows function at the bottom:


//set row -- colmun...
$iRow=5;
$sCol="A";

// repeat coloumn headings for every new page...
$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(4, 5);

 

//write column headings....
$sIndex = $sCol . $iRow;
$objPHPExcel->getActiveSheet()->setCellValue($sIndex, 'heading1');
$objPHPExcel->getActiveSheet()->getStyle($sIndex)->applyFromArray($aFormats['acolheading_noborder_Alignleft']);
$sCol++;

$sIndex = $sCol . $iRow;
$objPHPExcel->getActiveSheet()->setCellValue($sIndex, 'heading2');
$objPHPExcel->getActiveSheet()->getStyle($sIndex)->applyFromArray($aFormats['acolheading_noborder_Alignleft']);
$sCol++;

$sIndex = $sCol . $iRow;
$objPHPExcel->getActiveSheet()->setCellValue($sIndex, 'heading3');
$objPHPExcel->getActiveSheet()->getStyle($sIndex)->applyFromArray($aFormats['acolheading_noborder_Alignleft']);
$sCol++;

$sIndex = $sCol . $iRow;
$objPHPExcel->getActiveSheet()->setCellValue($sIndex, 'heading4');
$objPHPExcel->getActiveSheet()->getStyle($sIndex)->applyFromArray($aFormats['acolheading_noborder_Alignleft']);

// repeat coloumn headings for every new page...
$objPHPExcel->getActiveSheet()->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd($iRow, $iRow);

I can't seem to see where I am going wrong! Am I missing some additional code?

Many Thanks In Advance for your help
Bob

Developer
Jan 14, 2010 at 11:40 AM

I don't see anything wrong with your code.

Here is a simple test which I just tried and it worked fine with PHPExcel 1.7.2:

 

$excel = new PHPExcel();

$worksheet = $excel->getActiveSheet();
$worksheet->getCell('A1')->setValue('heading');

for ($i = 2; $i < 300; $i++) {
    $worksheet->getCell("A$i")->setValue("test$i");
}

$worksheet->getPageSetup()->setRowsToRepeatAtTopByStartAndEnd(1, 1);

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
$writer->save('write.xlsx');