我正在将现有的/工作应用程序从PHPExcel (phpoffice/phpexcel: 1.8.0)迁移到PHPSpreadsheet,在生成包含、一个或多个图表的文件时遇到了一个问题。
如果没有任何addChart调用,则生成的文件是有效的,但一旦添加图表,生成的文件就无效。Excel确实尝试恢复数据,该数据成功但没有图表。
Excel恢复工具显示:
Excel completed file level validation and repair.
Some parts of this workbook may have been repaired or discarded.
Removed Part: /xl/drawings/drawing1.xml part. (Drawing shape)当前使用:PHP7.1和phpoffice/phpspreadsheet: "1.10.1"
我的代码非常类似于我试图添加的PieChart示例。
生成PieChart的代码的一部分:
$ageCounterRowIndex值为6$expectedPointCount的值为4D3:D6中。E3:E6中$dataSeriesLabels = [];
$xAxisTickValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, "$quotedSheetTitle\$D\$3:\$D\$$ageCounterRowIndex", $expectedPointCount)
];
$dataSeriesValues = [
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, "$quotedSheetTitle\$E\$3:\$E\$$ageCounterRowIndex", $expectedPointCount),
];
$dataSeries = new DataSeries(
DataSeries::TYPE_PIECHART,
NULL,
range(0, count($dataSeriesValues) - 1),
$dataSeriesLabels,
$xAxisTickValues,
$dataSeriesValues
);
$pieLayout = new Layout();
$pieLayout->setShowVal(TRUE)->setShowPercent(TRUE);
$plotArea = new PlotArea($pieLayout, [ $dataSeries ]);
$legend = new Legend(Legend::POSITION_RIGHT, NULL, FALSE);
$chart = new Chart(
'piechart_' . ($sheetIndex - 1),
null,
$legend,
$plotArea,
true,
0,
NULL,
NULL
);
$chart->setTopLeftPosition('G2');
$chart->setBottomRightPosition('L15');
$sheet->addChart($chart);发布于 2020-04-22 22:20:08
将新图表调用中的displayBlanksAs参数从0更改为'gap'解决了这个问题。
我在PhpSpreadsheet存储库上找到了一份关于它的错误报告
$chart = new Chart(
'piechart_' . ($sheetIndex - 1),
null,
$legend,
$plotArea,
true,
0,
NULL,
NULL
);变成了
$chart = new Chart(
'piechart_' . ($sheetIndex - 1),
null,
$legend,
$plotArea,
true,
'gap',
NULL,
NULL
);https://stackoverflow.com/questions/59694440
复制相似问题