print excel file

Topics: User Forum
Apr 7, 2009 at 4:28 AM
Edited Apr 7, 2009 at 5:29 AM
hi there

I need to print 30 horizontal cells into same page. From the MS Excel 2007 I can do that in view->Page Break View-> move the blue line separator with mouse.

How to do that using PHPExcel lib?
Developer
Apr 8, 2009 at 9:46 AM
You will probably want to do this using:

$objWorksheet->setBreak('A30', PHPExcel_Worksheet::BREAK_ROW);

Apr 8, 2009 at 6:47 PM
i was trying but without success. the row break is made but not the column. Why?
    $objPHPExcel->getActiveSheet()->setBreak( 'A35' , PHPExcel_Worksheet::BREAK_ROW );
    $objPHPExcel->getActiveSheet()->setBreak( 'Z35' , PHPExcel_Worksheet::BREAK_COLUMN );  

one more question: Do I have to setup the page size and orientation for each sheet?


Developer
Apr 9, 2009 at 5:08 PM
Hmm... I tried your code:

    $objPHPExcel->getActiveSheet()->setBreak( 'A35' , PHPExcel_Worksheet::BREAK_ROW );
    $objPHPExcel->getActiveSheet()->setBreak( 'Z35' , PHPExcel_Worksheet::BREAK_COLUMN );

This gives me a horizontal page break after row 35, and a vertical page break before column Z. Not sure why it is working for me?

Yes, you have to set page size and orientation for each sheet.

Apr 19, 2009 at 7:19 PM
I have no idea about why this doen;t work for me......

On 35 columns I have 3 pages( 3 BREAK_COLUMN )

my code:
    $objPageSetup = new PHPExcel_Worksheet_PageSetup();
    $objPageSetup->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
    $objPageSetup->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
    $objPHPExcel->getActiveSheet()->setBreak( 'A35' , PHPExcel_Worksheet::BREAK_ROW );
    $objPHPExcel->getActiveSheet()->setBreak( 'Z35' , PHPExcel_Worksheet::BREAK_COLUMN );
    $objPageSetup->setFitToWidth(1);
    $objPHPExcel->getActiveSheet()->setPageSetup($objPageSetup);

many thx
Developer
Apr 21, 2009 at 3:17 PM
Edited Apr 21, 2009 at 3:18 PM
This may be a peculiar thing about Excel rather than PHPExcel. The page setup features can be set individually, but not all values can co-exist.  There can be over-constraining and special rules are needed to determine how pages are actually split. In your example it is probably setFitToWidth(1) that is preventing the page break to take effect.

Best advice is probably to first create your workbook in MS Office Excel the way you want it until you find the correct settings. Then apply the appropriate page setup values to your script in PHPExcel. To get the effect you want, you may need to adjust the page zoom rather than fit-to-width.