我有一个很大的问题,我需要用图表创建一个excel,但是当执行该函数时,创建excel但不会绘制图表。
功能是
function excel_get(){
$this->load->library('Classes/PHPExcel');
$this->phpexcel->getActiveSheet()->setTitle('Nombre de la hoja');
$this->phpexcel->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),
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$C$1', NULL, 1),
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$D$1', NULL, 1)
);
$xAxisTickValues = array(
new PHPExcel_Chart_DataSeriesValues('String', 'Worksheet!$A$2:$A$5', NULL, 4)
);
$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)
);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART,
PHPExcel_Chart_DataSeries::GROUPING_STANDARD,
range(0, count($dataSeriesValues)-1),
$dataseriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotarea = new PHPExcel_Chart_PlotArea(NULL, array($series));
$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 qwerty');
//Create the chart
$chart = new PHPExcel_Chart(
'chart1',
$title,
$legend,
$plotarea,
true,
0,
NULL,
$yAxisLabel
);
$this->phpexcel->getActiveSheet()->addChart($chart);
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setIncludeCharts(TRUE);
$writer->save('php://output');
}
PD:表格生成正确。
请帮帮我,问候。
答案 0 :(得分:0)
图表仅适用于OfficeOpenXML(.xlsx)格式文件的Excel2007
Reader / Writer
答案 1 :(得分:0)
我很抱歉,我刚刚发现它总能正常工作,但左上角的图表非常非常小,我没有看到它。
现在我的问题是显示最小宽度和高度的图表。