How to use print ready functionality in PHPExcel library

随声附和 提交于 2019-12-21 04:28:20

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/29026645/how-to-use-print-ready-functionality-in-phpexcel-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!