我必须开发一个程序,该程序包括创建包含不同单元格的新 Excel 工作表。下一步是生成一个垂直条形图来显示从数据单元格中检索到的各种数据。
我正在使用 PHPExcel 给出的“33chartcreate-column”示例来了解 libraty 如何与 codeigniter 框架一起工作。但是,当我尝试通过调用 setIncludeCharts 方法来创建图表时,我收到错误消息:“致命错误:在第 3327 行的* \application\third_party\PHPExcel\Calculation.php中的非对象上调用成员函数 cellExists() "
$this->load->library('excel');
//activate worksheet number 1
$this->excel->setActiveSheetIndex(0);
//name the worksheet
$this->excel->getActiveSheet()->setTitle('Nombre de la hoja');
$this->excel->getActiveSheet()->fromArray(
array(
array('', 2010, 2011, 2012),
array('Q1', 12, 15, 21),
array('Q2', 56, 73, 86),
array('Q3', 52, 61, 69),
array('Q4', 30, 32, 0),
)
);
$dataseriesLabels = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$B$1', NULL, 1), // 2010
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1), // 2011
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1), // 2012
);
/*Set the X-Axis Labels
Datatype
Cell reference for data
Format Code
Number of datapoints in series
Data values
Data Marker*/
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4), // Q1 to Q4
);
/*Set the Data values for each data series we want to plot
Datatype
Cell reference for data
Format Code
Number of datapoints in series
Data values
Data Marker*/
$dataSeriesValues = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$B$2:$B$5', NULL, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$D$2:$D$5', NULL, 4),
);
//Build the dataseries
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_STANDARD, // plotGrouping
range(0, count($dataSeriesValues)-1), // plotOrder
$dataseriesLabels, // plotLabel
$xAxisTickValues, // plotCategory
$dataSeriesValues // plotValues
);
/*Set additional dataseries parameters
Make it a vertical column rather than a horizontal bar graph*/
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
//Set the series in the plot area
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series));
//Set the chart legend
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL,false);
$title = new PHPExcel_Chart_Title('Test Column Chart');
$yAxisLabel = new PHPExcel_Chart_Title('Value ($k)');
//Create the chart
$chart = new PHPExcel_Chart(
'chart1', // name
$title, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
NULL, // xAxisLabel
$yAxisLabel // yAxisLabel
);
$this->excel->getActiveSheet()->addChart($chart);
// Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
<b>$objWriter->setIncludeCharts(TRUE);</b> //line 1327
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));