【发布时间】:2013-12-02 12:13:59
【问题描述】:
当我在工作表名称中添加一个空格时,图表开始产生错误。
有效
$heading = 'AB';
问题:为什么不起作用?
$heading = 'A B'; //i want to give a space in sheet name how?
完整代码:
$workbook = new PHPExcel();
$heading = 'AB';
$workbook->getActiveSheet()->setTitle($heading);
// Set document properties
$sheet = $workbook->getActiveSheet();
$sheet->fromArray(array(
array( '', 2010, 2011),
array('Q1', 12, 15),
array('Q2', 56, 73),
array('Q3', 52, 61),
array('Q4', 30, 32),
));
$labels = array(
new PHPExcel_Chart_DataSeriesValues('String', $heading.'!$B$1', null, 1),
new PHPExcel_Chart_DataSeriesValues('String', $heading.'!$C$1', null, 1),
);
$categories = array(
new PHPExcel_Chart_DataSeriesValues('String', $heading.'!$A$2:$A$5', null, 4),
new PHPExcel_Chart_DataSeriesValues('String', $heading.'!$A$2:$A$5', null, 4),
);
$values = array(
new PHPExcel_Chart_DataSeriesValues('Number', $heading.'!$B$2:$B$5', null, 4),
new PHPExcel_Chart_DataSeriesValues('Number', $heading.'!$C$2:$C$5', null, 4),
);
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_BARCHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
array(0, 1), // plotOrder
$labels, // plotLabel
$categories, // plotCategory
$values // plotValues
);
$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);
$chart = new PHPExcel_Chart(
'chart1', // name
null, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
null, // xAxisLabel
null // yAxisLabel
);
$chart->setTopLeftPosition('A7');
$chart->setBottomRightPosition('H20');
$sheet->addChart($chart);
$writer = PHPExcel_IOFactory::createWriter($workbook, 'Excel2007');
$writer->setIncludeCharts(TRUE);
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="polls_and_feedback_'.time().'.xlsx"');
$writer->save('php://output');
【问题讨论】: