Jov*_*vic 3 excel php-7 phpspreadsheet
我正在将现有/工作应用程序从PHPExcel( phpoffice/phpexcel: 1.8.0) 迁移到,并且在生成包含一个或多个图表的PHPSpreadsheetExcel 文件时遇到问题。
没有任何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)
Run Code Online (Sandbox Code Playgroud)
当前使用:PHP 7.1 和phpoffice/phpspreadsheet: "1.10.1"
我的代码与我尝试添加的 PieChart 示例非常相似。
生成饼图的部分代码:
$ageCounterRowIndex值为 6$expectedPointCount值为 4D3:D6E3: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);
Run Code Online (Sandbox Code Playgroud)
更改displayBlanksAs新图表调用中的参数为我解决了这个问题0。'gap'
我在PhpSpreadsheet 存储库上找到了有关它的错误报告
$chart = new Chart(
'piechart_' . ($sheetIndex - 1),
null,
$legend,
$plotArea,
true,
0,
NULL,
NULL
);
Run Code Online (Sandbox Code Playgroud)
变成
$chart = new Chart(
'piechart_' . ($sheetIndex - 1),
null,
$legend,
$plotArea,
true,
'gap',
NULL,
NULL
);
Run Code Online (Sandbox Code Playgroud)