Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use print ready functionality in PHPExcel library

I am using PHPExcel library for spreadsheet operations. I am to apply print ready functionality. Does this functionality exist?

like image 756
Vaishnavesh Avatar asked Mar 13 '15 07:03

Vaishnavesh


People also ask

How to write xlsx file in PHP?

You may use the following code: header('Content-Type: application/vnd. ms-excel'); header('Content-Disposition: attachment;filename="file. xlsx"'); header('Cache-Control: max-age=0'); $writer->save('php://output');

How to create spreadsheet in PHP?

If you want to create a new workbook, rather than load one from file, then you simply need to instantiate it as a new Spreadsheet object. /** Create a new Spreadsheet Object **/ $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); A new workbook will always be created with a single worksheet.


1 Answers

If you read the documentation, particularly the section entitled "Setting printer options for Excel files", there's a lot of information about page setup for printing:-

Orientation and Paper Size:

$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);
$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

Page margins:

$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setTop(1);
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setRight(0.75);
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setLeft(0.75);
$objPHPExcel->getActiveSheet()
    ->getPageMargins()->setBottom(1);

Headers and Footers:

$objPHPExcel->getActiveSheet()
    ->getHeaderFooter()
    ->setOddHeader('&C&HPlease treat this document as confidential!');
$objPHPExcel->getActiveSheet()
    ->getHeaderFooter()
    ->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . 

Printer page breaks:

$objPHPExcel->getActiveSheet()
    ->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );

Showing grid lines:

$objPHPExcel->getActiveSheet()
    ->setShowGridlines(true);

Setting rows/columns to repeat at the top/left of each page

$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setRowsToRepeatAtTopByStartAndEnd(1, 5);

Setting the print area:

$objPHPExcel->getActiveSheet()
    ->getPageSetup()
    ->setPrintArea('A1:E5,G4:M20');

We write the documentation so that you don't have to ask questions like this

like image 94
Mark Baker Avatar answered Oct 05 '22 13:10

Mark Baker