graphs from excel template

Topics: Project Management Forum
Jun 10, 2013 at 3:09 PM
Hello,
I'm programming a library that uses a template with graphics that are filled dynamically from php.

With PHPExcel only fill the cells that the chart will use.

is it possible?

I have done tests but once created. xls, open the file, but the graphics are gone.

what happens?

Here the last fragment of code:

$nombreEnt=$_POST['nombreEntidad'];
$direccionEnt=$_POST['direccionEntidad'];
$fehaInforme="Informe de ".date("d-m-Y");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A29', $nombreEnt)
->setCellValue('A30', $direccionEnt)
->setCellValue('A31', $fehaInforme);

$nameEntiFile=str_replace(' ', '', $_POST['nombreEntidad']);
$nameFile=date("Y-m-d").$nameEntiFile.".xls";

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$nameFile.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

thank you very much
Jun 10, 2013 at 5:11 PM
I've been reading about this bug and it looks like I use excel5.

I did a test with this code and it does not work. I download the template but I deleted the graph that existed in the template.

I copy the code for if you can help:
<?php

require_once '../lib/excel/PHPExcel.php'; 
 
 /** Error reporting */
error_reporting(E_ALL);


$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("plantillaTest.xlsx");


 $objPHPExcel->setActiveSheetIndex(0)
        //duplicamos el estilo de una celda o un rango de ellas
        //->duplicateStyle($objPHPExcel->getActiveSheet()->getStyle('B6'),'B'.$i)   
        ->setCellValue('A1', 6)                                 
        ->setCellValue('A2', 7)
        ->setCellValue('A3', 8);


ob_end_clean();//inprescindible
        
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Report.xlsx"');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();//inprescindible


$objWriter->save('php://output');

?>
Coordinator
Jun 14, 2013 at 12:22 PM
You specifically need to tell PHPExcel to include charts, both when loading a file and when saving:
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load($inputFileName);
and
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
And you're correct - currently only the Excel2007 Reader and Writer support charts