当我尝试添加图形时,PhpSpreadsheet出现致命错误



致命错误:未捕获的PhpOffice\PhpSpreadsheet\Calculation\Exception:公式错误:中发生意外错误C: \examplep\htdocs\graficas_excel\vendor\phpoffice\phpelectroledata\src\phpspreadsheet\Calculation\Calculation.php:5224
堆栈跟踪:
#0C: \examplep\htdocs\graficas_excel\vendor\phpoffice\phpelectroledata\src\phpspreadsheet\Calculation\Calculation.php(4305(:PhpOffice\PhpSpreadsheet\计算\计算->存在公式错误("公式错误:…'(
#1C: \examplep\htdocs\graficas_excel\vendor\phpoffice\phpelectroledata\src\phpspreadsheet\Calculation\Calculation.php(3539(:PhpOffice\PhpSpreadsheet\计算\计算->internalParseFormula('!工作表$B.…',对象(PhpOffice\PhpSpreadsheet\Cell\Cell(
#2C: \examplep\htdocs\graficas_excel\vendor\phpoffice\phpelectroledata\src\phpspreadsheet\Chart\DataSeriesValues.php(363(:PhpOffice\PhpSpreadsheet\计算\计算-&gt_calculateFormulaValue('!工作表$B.…',NULL,对象(PhpOffice\PhpSpreadsheet\Cell\Cell(
#3 C:\xamplep\htdocs\graficas_excel\vendor\phpoffice\phpspreadsh中的C:\xamplep \htdocs \graficas-excel\vendor\phpoffice \phpspread \src\phpspreadsheet\Calculation\Calculation.php在线5224

大家好。

我试着在excel中为phpoffice/phpelectronicsheet创建图表,但当我尝试添加图表时,应用程序坏了。

我的代码

<?php
require '../vendor/autoload.php';
use PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;
use PhpOfficePhpSpreadsheetChartChart;
use PhpOfficePhpSpreadsheetChartDataSeries;
use PhpOfficePhpSpreadsheetChartDataSeriesValues;
use PhpOfficePhpSpreadsheetChartLayout;
use PhpOfficePhpSpreadsheetChartLegend;
use PhpOfficePhpSpreadsheetChartPlotArea;
use PhpOfficePhpSpreadsheetChartTitle;
use PhpOfficePhpSpreadsheetChartAxis;
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray(
[
['Shinjuku', 778, 618],
['Ikebukuro', 566, 516],
[' Tokyo ', 452, 549],
[' Shinagawa ', 378, 566],
[' Shibuya ', 370, 669],
]
);
$xAxisTickValues = [
New DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_STRING, '! Worksheet $ A $ 1: $ A $ 5', Null, 5), //Shinjuku-Shibuya
];
$dataSeriesValues = [
New DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_NUMBER, '! Worksheet $ B $ 1: $ B $ 5', Null, 5), //each value of the number of passengers
];
$series = new DataSeries(
DataSeries::TYPE_BARCHART, //plotType
DataSeries::GROUPING_STANDARD, //plotGrouping
range(0, count($dataSeriesValues) - 1), //plotOrder
[], //plotLabel
$xAxisTickValues, //plotCategory
$dataSeriesValues//plotValues
);
$series->setPlotDirection(DataSeries::DIRECTION_COL);
$plotArea = new PlotArea(null, [$series]);
$title = new Title('number of passengers per day');
$yaxis = new Axis();
$xaxis = new Axis();
$yaxis->setAxisOptionsProperties('low', null, null, null, null, null, 0, 100, null, null);
$yaxis->setLineParameters('FFFFFF', 100, Axis::EXCEL_COLOR_TYPE_ARGB);
$xaxis->setAxisOptionsProperties('low', null, null, null, null, null, 0, 0, null, null);
$legend1 = new Legend(Legend::POSITION_RIGHT, null, false);
$yAxisLabel = new Title('');
$chart = new Chart(
'bar chart', //name
$title, //title
$legend1, //legend
$plotArea, //plotArea
true, //plotVisibleOnly
DataSeries::EMPTY_AS_GAP, // displayBlanksAs
null, // xAxisLabel
$yAxisLabel, // yAxisLabel
$yaxis,
$xaxis
);
$worksheet->addChart($chart);
$writer = new Xlsx($spreadsheet);
$writer->setIncludeCharts(true);
$writer->save('passengers.xlsx');

我已经更改了代码。

$worksheet->fromArray(
[
['', 'number of passengers per day',''],
['Shinjuku', 7787.81, 618],
['Ikebukuro ', 566, 516],
[' Tokyo ', 452, 549],
[' Shinagawa ', 378, 566],
[' Shibuya ', 370, 669],
]
);
$xAxisTickValues = [
New DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$6', Null, 5), //Shinjuku-Shibuya
];
$dataSeriesValues = [
New DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_NUMBER, 'Worksheet!$B$2:$B$6', Null, 5), //each value of the number of passengers
New DataSeriesValues(DataSeriesValues :: DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$6', Null, 5), //each value of the number of passengers
];

这是可行的,但当我打开excel时,我需要恢复表单xml错误?

相关内容

  • 没有找到相关文章

最新更新