PHPExcel – Excel5 – Create Line Chart – Chart Missing

chartsPHPphpexcel

Reject? I am sure I am not the first that has ran into this issue.

I am trying to create a chart using PHPExcel and the Excel5 library to produce an .xls file of the '95 format.

All goes well except for the creation/save of the chart itself. The file is saved/downloaded/opened without any errors alerted by either, PHPExcel during creation/save, or by Excel during opening the file.

The only real issue is, there is no chart visible within the Excel '95 .xls file created.

I have checked to be sure the MIME type is being set to the '95 .xls format application/vnd.ms-excel. It is.

Here is the code relating to the chart creation, its a little messy currently, but like I said, works like a charm for the 2007 version:

//ADD THE REPORT SUMMARY CHART
$labels = array(
    new PHPExcel_Chart_DataSeriesValues('String', "'Report Summary'!C1", null, 1),
    new PHPExcel_Chart_DataSeriesValues('String', "'Report Summary'!D1", null, 1)
);
$chrtCols = "'Report Summary'!B2:B$rowNum";
$chrtVals = "'Report Summary'!C2:C$rowNum";
$chrtVals2 = "'Report Summary'!D2:D$rowNum";
$periods = new PHPExcel_Chart_DataSeriesValues('String', $chrtCols, null, $rowNum-1);
$values = new PHPExcel_Chart_DataSeriesValues('Number', $chrtVals, null, $rowNum-1);
$values2 = new PHPExcel_Chart_DataSeriesValues('Number', $chrtVals2, null, $rowNum-1);
$series = new PHPExcel_Chart_DataSeries(
    PHPExcel_Chart_DataSeries::TYPE_LINECHART,       
    PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  
    array(0,1),                                       
    $labels,                                       
    array($periods,$periods),                               
    array($values,$values2)                                  
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$layout = new PHPExcel_Chart_Layout();

$plotarea = new PHPExcel_Chart_PlotArea($layout, array($series));
$chart = new PHPExcel_Chart('sample', null, null, $plotarea);
$chart->setTopLeftPosition('A1', 24, 24);
$chart->setBottomRightPosition('B18', -24);
$actSheet->addChart($chart);

The issue seems to be with the '95 version only as the exact same code works to create a valid 2007 version of the file (using the Excel_2007 class rather than Excel5).

Any thoughts? Are line-charts constructed differently (or labels defined differently) in Excel_07 as compared to Excel_95? Any other declarations in the $series array I should add/modify/delete to get the chart to appear Excel_95?

Yes, I am including $objWriter->setIncludeCharts(TRUE); prior to writing the file.

$rowNum is the last row of data.

Best Answer

PHPExcel only supports charts for the Excel2007 Reader/Writer; that feature has not been written for the Excel5 Reader/Writer

Related Topic