我一直坚持这个问题一段时间了。我似乎无法弄明白的方式。我无法获得PHPExcel的饼图示例 33chartcreate-pie.php 。我到处搜索,但我似乎无法找到一个好的答案,所以我决定自己问一下。从给出的示例中,我尝试了这个..我正在使用Codeigniter,因此我正在加载库$this->load->library('excel')
。
$dataseriesLabel1 = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),
);
$xAxisTickValues1 = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4),
);
$dataSeriesValues1 = array(
new PHPExcel_Chart_DataSeriesValues('Number', 'Worksheet!$C$2:$C$5', NULL, 4),
);
$series1 = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_PIECHART,
PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
range(0, count($dataSeriesValues1)-1),
$dataseriesLabels1,
$xAxisTickValues1,
$dataSeriesValues1
);
$layout1 = new PHPExcel_Chart_Layout();
$layout1->setShowVal(TRUE);
$layout1->setShowPercent(TRUE);
$plotarea1 = new PHPExcel_Chart_PlotArea($layout1, array($series1));
$legend1 = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_RIGHT, NULL, false);
$title1 = new PHPExcel_Chart_Title('Test Pie Chart');
$chart1 = new PHPExcel_Chart(
'chart1',
$title1,
$legend1,
$plotarea1,
true,
0,
NULL,
NULL
);
$chart1->setTopLeftPosition('A7');
$chart1->setBottomRightPosition('H20');
$this->excel->getActiveSheet()->addChart($chart1);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content_Disposition: attachment;filename="Report"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
起初,我没有得到任何输出,然后我发现我使用 Excel5 。所以,我将类型更改为 Excel2007 ,但我仍然没有得到任何结果。事实上,当我导出并将扩展名从 .xlsx 更改为 .xls 时,我收到以下错误:
<b>Fatal error</b>: Call to a member function cellExists() on a non-object in <b>path\application\third_party\PHPExcel\Calculation.php</b> on line <b>3327</b><br />
我真的很感激帮助。谢谢你看这个。我希望一切都清楚。
答案 0 :(得分:1)
这项工作对我来说
而不是:$this->excel
使用:
$objPHPExcel
(但首先$objPHPExcel = new PHPExcel();
)
而不是:header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
使用:
header('Content-Type: application/vnd.ms-excel');
而不是:header('Content_Disposition: attachment;filename="Report"');
使用:header('Content-Disposition: attachment;filename="Report.xls"');