I need to generate a report with graphs in excel to pdf. I tried using phpexcel but it fails to load the charts. It only generates PDF with tables. Here's my code in phpexcel.
$newpdf = "report-".date('m_d_Y_H_i_s', strtotime('now')).".pdf";
$objPHPExcel1 = new PHPExcel();
$objPHPExcel1 = PHPExcel_IOFactory::load('csv/'.$filename);
$objPHPExcel1->getActiveSheet(0)->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
$objPHPExcel1->getActiveSheet(0)->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$objPHPExcel1->getActiveSheet(0)->getPageSetup()->setFitToWidth(true);
$objPHPExcel1->getActiveSheet(0)->getPageSetup()->setFitToHeight(true);
$objPHPExcel1->getActiveSheet()->setShowGridLines(false);
header('Content-Type: application/pdf');
header('Content-Disposition: attachment;filename="'.$newpdf.'"');
header('Cache-Control: max-age=0'); //no cache
$objWriter1 = new PHPExcel_Writer_PDF($objPHPExcel1);
$objWriter1->save('php://output');
exit;
I also tried loading the contents from HTML using jchartfx for graphs without success. Any idea?
Thanks in advance.
PHPExcel can only read charts from Excel2007 (OfficeOpenXML .xlsx) files, and will only load them if you explicitly tell it to do so.
When writing to a PDF file, you must have the relevant library installed (tcpdf in your case) and tell PHPExcel that you want to use it and the directory where tcpdf is installed.
You also need jpgraph installed, and again PHPExcel needs to know where it is installed
Finally, you need to tell the PDF Writer explicitly to generate the charts