convert excel template to pdf

Topics: Developer Forum
Dec 10, 2010 at 7:42 PM

How would i convert excel template to a pdf after i input the data and output to the browser.

It worked fine with excel, but when converting to pdf it does not work.

 

/** Error reporting */
            error_reporting(E_ALL);

            date_default_timezone_set('Europe/London');

            /** PHPExcel */
            require_once ('/home/scav/public_html/admin/php/classes/PHPExcel.php');

            $objPHPexcel = PHPExcel_IOFactory::load('/home/scav/public_html/admin/templates/excel/invoicetemplate.xls');

            // redirect output to client browser
            header('Content-Type: application/vnd.ms-excel');
            header('Content-Disposition: attachment;filename="membership.xls"');
            header('Cache-Control: max-age=0');

            $objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');


        $objWorksheet = $objPHPexcel->getActiveSheet();
                $objWorksheet->setCellValueByColumnAndRow(0, 1, 'hi');
                $objWorksheet->setCellValueByColumnAndRow(1, 2, post('first_name'));
                $objWorksheet->setCellValueByColumnAndRow(2, 3, post('test'));
                $objWorksheet->setCellValueByColumnAndRow(3, 4, 'wtf');


           
            $objWriter = new PHPExcel_Writer_PDF($objPHPexcel);
      $objWriter->setPreCalculateFormulas(false);
      //$objWriter->save('php://output');
     $objWriter->save("php://output");
 

    }

Coordinator
Dec 10, 2010 at 7:50 PM
Edited Dec 10, 2010 at 7:51 PM

You need to send the appropriate headers for a PDF file. Take a look at the 01simple-download-pdf.php file in the /Tests directory

header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="membership.pdf"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'PDF');
$objWriter->setPreCalculateFormulas(false);
$objWriter->save('php://output');
Dec 10, 2010 at 7:55 PM

thanks that worked, forgot about those headers.

 

Also, the images are gone. Are images supported?

And the file looks like a worksheet, how can i get rid of all those gridlines?

Coordinator
Dec 10, 2010 at 10:39 PM
mace519 wrote:

Also, the images are gone. Are images supported?

This is a known issue: see work item 9985

mace519 wrote:

And the file looks like a worksheet, how can i get rid of all those gridlines?

 Are you running PHPExcel 1.7.4 or 1.7.5?

Dec 13, 2010 at 12:51 PM

1.75

Dec 13, 2010 at 1:01 PM

also, when adding borders in an excel template, when converted to pdf the borders leave a gap between where the excel cells were.