I am using PHPExcel library for spreadsheet operations. I am to apply print ready functionality. Does this functionality exist?
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');
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With