Skip to content

Commit 01d2d54

Browse files
authored
Merge branch 'master' into Performance-Refresh-Row/Column-Dimensions
2 parents 715b50a + 5d5e550 commit 01d2d54

37 files changed

+1452
-392
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
4949
- Time interval formatting [Issue #2768](https://github.com/PHPOffice/PhpSpreadsheet/issues/2768) [PR #2772](https://github.com/PHPOffice/PhpSpreadsheet/pull/2772)
5050
- Copy from Xls(x) to Html/Pdf loses drawings [PR #2788](https://github.com/PHPOffice/PhpSpreadsheet/pull/2788)
5151
- Html Reader converting cell containing 0 to null string [Issue #2810](https://github.com/PHPOffice/PhpSpreadsheet/issues/2810) [PR #2813](https://github.com/PHPOffice/PhpSpreadsheet/pull/2813)
52-
- Many fixes for Charts, especially, but not limited to, Scatter, Bubble, and Surface charts. [Issue #2762](https://github.com/PHPOffice/PhpSpreadsheet/issues/2762) [Issue #2299](https://github.com/PHPOffice/PhpSpreadsheet/issues/2299) [Issue #2700](https://github.com/PHPOffice/PhpSpreadsheet/issues/2700) [Issue #2817](https://github.com/PHPOffice/PhpSpreadsheet/issues/2817) [Issue #2763](https://github.com/PHPOffice/PhpSpreadsheet/issues/2763) [Issue #2219](https://github.com/PHPOffice/PhpSpreadsheet/issues/2219) [PR #2828](https://github.com/PHPOffice/PhpSpreadsheet/pull/2828) [PR #2841](https://github.com/PHPOffice/PhpSpreadsheet/pull/2841) [PR #2846](https://github.com/PHPOffice/PhpSpreadsheet/pull/2846) [PR #2852](https://github.com/PHPOffice/PhpSpreadsheet/pull/2852) [PR #2856](https://github.com/PHPOffice/PhpSpreadsheet/pull/2856) [PR #2865](https://github.com/PHPOffice/PhpSpreadsheet/pull/2865) [PR #2872](https://github.com/PHPOffice/PhpSpreadsheet/pull/2872) [PR #2879](https://github.com/PHPOffice/PhpSpreadsheet/pull/2879)
52+
- Many fixes for Charts, especially, but not limited to, Scatter, Bubble, and Surface charts. [Issue #2762](https://github.com/PHPOffice/PhpSpreadsheet/issues/2762) [Issue #2299](https://github.com/PHPOffice/PhpSpreadsheet/issues/2299) [Issue #2700](https://github.com/PHPOffice/PhpSpreadsheet/issues/2700) [Issue #2817](https://github.com/PHPOffice/PhpSpreadsheet/issues/2817) [Issue #2763](https://github.com/PHPOffice/PhpSpreadsheet/issues/2763) [Issue #2219](https://github.com/PHPOffice/PhpSpreadsheet/issues/2219) [Issue #2863](https://github.com/PHPOffice/PhpSpreadsheet/issues/2863) [PR #2828](https://github.com/PHPOffice/PhpSpreadsheet/pull/2828) [PR #2841](https://github.com/PHPOffice/PhpSpreadsheet/pull/2841) [PR #2846](https://github.com/PHPOffice/PhpSpreadsheet/pull/2846) [PR #2852](https://github.com/PHPOffice/PhpSpreadsheet/pull/2852) [PR #2856](https://github.com/PHPOffice/PhpSpreadsheet/pull/2856) [PR #2865](https://github.com/PHPOffice/PhpSpreadsheet/pull/2865) [PR #2872](https://github.com/PHPOffice/PhpSpreadsheet/pull/2872) [PR #2879](https://github.com/PHPOffice/PhpSpreadsheet/pull/2879) [PR #2898](https://github.com/PHPOffice/PhpSpreadsheet/pull/2898) [PR #2906](https://github.com/PHPOffice/PhpSpreadsheet/pull/2906)
5353
- Calculating Engine regexp for Column/Row references when there are multiple quoted worksheet references in the formula [Issue #2874](https://github.com/PHPOffice/PhpSpreadsheet/issues/2874) [PR #2899](https://github.com/PHPOffice/PhpSpreadsheet/pull/2899)
5454

5555
## 1.23.0 - 2022-04-24

phpstan-baseline.neon

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,16 +4055,6 @@ parameters:
40554055
count: 1
40564056
path: src/PhpSpreadsheet/Writer/Xlsx.php
40574057

4058-
-
4059-
message: "#^Cannot call method getDataValues\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeriesValues\\|false\\.$#"
4060-
count: 1
4061-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4062-
4063-
-
4064-
message: "#^Cannot call method getFillColor\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeriesValues\\|false\\.$#"
4065-
count: 1
4066-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
4067-
40684058
-
40694059
message: "#^Parameter \\#1 \\$plotSeriesValues of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writeBubbles\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeriesValues\\|null, PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeriesValues\\|false given\\.$#"
40704060
count: 1
@@ -4087,7 +4077,7 @@ parameters:
40874077

40884078
-
40894079
message: "#^Parameter \\#2 \\$value of method XMLWriter\\:\\:writeAttribute\\(\\) expects string, int given\\.$#"
4090-
count: 42
4080+
count: 41
40914081
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
40924082

40934083
-
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
use PhpOffice\PhpSpreadsheet\Chart\Chart;
4+
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
5+
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
6+
use PhpOffice\PhpSpreadsheet\Chart\Layout;
7+
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
8+
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
9+
use PhpOffice\PhpSpreadsheet\Chart\Title;
10+
use PhpOffice\PhpSpreadsheet\IOFactory;
11+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
12+
13+
require __DIR__ . '/../Header.php';
14+
15+
$spreadsheet = new Spreadsheet();
16+
$worksheet = $spreadsheet->getActiveSheet();
17+
$worksheet->fromArray(
18+
[
19+
['', 2010, 2011, 2012],
20+
['Q1', 12, 15, 21],
21+
['Q2', 56, 73, 86],
22+
['Q3', 52, 61, 69],
23+
['Q4', 30, 32, 0],
24+
]
25+
);
26+
27+
// Custom colors for dataSeries (gray, blue, red, orange)
28+
$colors = [
29+
'cccccc', '00abb8', 'b8292f', 'eb8500',
30+
];
31+
32+
// Set the Labels for each data series we want to plot
33+
// Datatype
34+
// Cell reference for data
35+
// Format Code
36+
// Number of datapoints in series
37+
// Data values
38+
// Data Marker
39+
$dataSeriesLabels1 = [
40+
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011
41+
];
42+
// Set the X-Axis Labels
43+
// Datatype
44+
// Cell reference for data
45+
// Format Code
46+
// Number of datapoints in series
47+
// Data values
48+
// Data Marker
49+
$xAxisTickValues1 = [
50+
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
51+
];
52+
// Set the Data values for each data series we want to plot
53+
// Datatype
54+
// Cell reference for data
55+
// Format Code
56+
// Number of datapoints in series
57+
// Data values
58+
// Data Marker
59+
// Custom colors
60+
$dataSeriesValues1 = [
61+
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4, [], null, $colors),
62+
];
63+
64+
// Build the dataseries
65+
$series1 = new DataSeries(
66+
DataSeries::TYPE_BARCHART, // plotType
67+
null, // plotGrouping (Pie charts don't have any grouping)
68+
range(0, count($dataSeriesValues1) - 1), // plotOrder
69+
$dataSeriesLabels1, // plotLabel
70+
$xAxisTickValues1, // plotCategory
71+
$dataSeriesValues1 // plotValues
72+
);
73+
74+
// Set up a layout object for the Pie chart
75+
$layout1 = new Layout();
76+
$layout1->setShowVal(true);
77+
$layout1->setShowPercent(true);
78+
79+
// Set the series in the plot area
80+
$plotArea1 = new PlotArea($layout1, [$series1]);
81+
// Set the chart legend
82+
$legend1 = new ChartLegend(ChartLegend::POSITION_RIGHT, null, false);
83+
84+
$title1 = new Title('Test Bar Chart');
85+
86+
// Create the chart
87+
$chart1 = new Chart(
88+
'chart1', // name
89+
$title1, // title
90+
$legend1, // legend
91+
$plotArea1, // plotArea
92+
true, // plotVisibleOnly
93+
DataSeries::EMPTY_AS_GAP, // displayBlanksAs
94+
null, // xAxisLabel
95+
null // yAxisLabel - Pie charts don't have a Y-Axis
96+
);
97+
98+
// Set the position where the chart should appear in the worksheet
99+
$chart1->setTopLeftPosition('A7');
100+
$chart1->setBottomRightPosition('H20');
101+
102+
// Add the chart to the worksheet
103+
$worksheet->addChart($chart1);
104+
105+
// Set the Labels for each data series we want to plot
106+
// Datatype
107+
// Cell reference for data
108+
// Format Code
109+
// Number of datapoints in series
110+
// Data values
111+
// Data Marker
112+
$dataSeriesLabels2 = [
113+
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011
114+
];
115+
// Set the X-Axis Labels
116+
// Datatype
117+
// Cell reference for data
118+
// Format Code
119+
// Number of datapoints in series
120+
// Data values
121+
// Data Marker
122+
$xAxisTickValues2 = [
123+
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$A$2:$A$5', null, 4), // Q1 to Q4
124+
];
125+
// Set the Data values for each data series we want to plot
126+
// Datatype
127+
// Cell reference for data
128+
// Format Code
129+
// Number of datapoints in series
130+
// Data values
131+
// Data Marker
132+
// Custom colors
133+
$dataSeriesValues2 = [
134+
$dataSeriesValues2Element = new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4),
135+
];
136+
$dataSeriesValues2Element->setFillColor($colors);
137+
138+
// Build the dataseries
139+
$series2 = new DataSeries(
140+
DataSeries::TYPE_DONUTCHART, // plotType
141+
null, // plotGrouping (Donut charts don't have any grouping)
142+
range(0, count($dataSeriesValues2) - 1), // plotOrder
143+
$dataSeriesLabels2, // plotLabel
144+
$xAxisTickValues2, // plotCategory
145+
$dataSeriesValues2 // plotValues
146+
);
147+
148+
// Set up a layout object for the Pie chart
149+
$layout2 = new Layout();
150+
$layout2->setShowVal(true);
151+
$layout2->setShowCatName(true);
152+
153+
// Set the series in the plot area
154+
$plotArea2 = new PlotArea($layout2, [$series2]);
155+
156+
$title2 = new Title('Test Donut Chart');
157+
158+
// Create the chart
159+
$chart2 = new Chart(
160+
'chart2', // name
161+
$title2, // title
162+
null, // legend
163+
$plotArea2, // plotArea
164+
true, // plotVisibleOnly
165+
DataSeries::EMPTY_AS_GAP, // displayBlanksAs
166+
null, // xAxisLabel
167+
null // yAxisLabel - Like Pie charts, Donut charts don't have a Y-Axis
168+
);
169+
170+
// Set the position where the chart should appear in the worksheet
171+
$chart2->setTopLeftPosition('I7');
172+
$chart2->setBottomRightPosition('P20');
173+
174+
// Add the chart to the worksheet
175+
$worksheet->addChart($chart2);
176+
177+
// Save Excel 2007 file
178+
$filename = $helper->getFilename(__FILE__);
179+
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
180+
$writer->setIncludeCharts(true);
181+
$callStartTime = microtime(true);
182+
$writer->save($filename);
183+
$helper->logWrite($writer, $filename, $callStartTime);

samples/Chart/33_Chart_create_line.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
66
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
77
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
8+
use PhpOffice\PhpSpreadsheet\Chart\Properties;
89
use PhpOffice\PhpSpreadsheet\Chart\Title;
910
use PhpOffice\PhpSpreadsheet\IOFactory;
1011
use PhpOffice\PhpSpreadsheet\Spreadsheet;
@@ -35,6 +36,7 @@
3536
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$C$1', null, 1), // 2011
3637
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_STRING, 'Worksheet!$D$1', null, 1), // 2012
3738
];
39+
$dataSeriesLabels[0]->setFillColor('FF0000');
3840
// Set the X-Axis Labels
3941
// Datatype
4042
// Cell reference for data
@@ -57,7 +59,7 @@
5759
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', null, 4),
5860
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', null, 4),
5961
];
60-
$dataSeriesValues[2]->setLineWidth(60000);
62+
$dataSeriesValues[2]->setLineWidth(60000 / Properties::POINTS_WIDTH_MULTIPLIER);
6163

6264
// Build the dataseries
6365
$series = new DataSeries(

samples/Chart/33_Chart_create_scatter2.php

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use PhpOffice\PhpSpreadsheet\Chart\Axis;
44
use PhpOffice\PhpSpreadsheet\Chart\Chart;
5+
use PhpOffice\PhpSpreadsheet\Chart\ChartColor;
56
use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
67
use PhpOffice\PhpSpreadsheet\Chart\DataSeriesValues;
78
use PhpOffice\PhpSpreadsheet\Chart\Legend as ChartLegend;
@@ -64,11 +65,76 @@
6465
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$C$2:$C$5', Properties::FORMAT_CODE_NUMBER, 4),
6566
new DataSeriesValues(DataSeriesValues::DATASERIES_TYPE_NUMBER, 'Worksheet!$D$2:$D$5', Properties::FORMAT_CODE_NUMBER, 4),
6667
];
68+
69+
// series 1
70+
// marker details
71+
$dataSeriesValues[0]
72+
->setPointMarker('diamond')
73+
->setPointSize(5)
74+
->getMarkerFillColor()
75+
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
76+
$dataSeriesValues[0]
77+
->getMarkerBorderColor()
78+
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
79+
80+
// line details - smooth line, connected
81+
$dataSeriesValues[0]
82+
->setScatterLines(true)
83+
->setSmoothLine(true)
84+
->setLineColorProperties('accent1', 40, ChartColor::EXCEL_COLOR_TYPE_SCHEME); // value, alpha, type
85+
$dataSeriesValues[0]->setLineStyleProperties(
86+
2.5, // width in points
87+
Properties::LINE_STYLE_COMPOUND_TRIPLE, // compound
88+
Properties::LINE_STYLE_DASH_SQUARE_DOT, // dash
89+
Properties::LINE_STYLE_CAP_SQUARE, // cap
90+
Properties::LINE_STYLE_JOIN_MITER, // join
91+
Properties::LINE_STYLE_ARROW_TYPE_OPEN, // head type
92+
Properties::LINE_STYLE_ARROW_SIZE_4, // head size preset index
93+
Properties::LINE_STYLE_ARROW_TYPE_ARROW, // end type
94+
Properties::LINE_STYLE_ARROW_SIZE_6 // end size preset index
95+
);
96+
97+
// series 2 - straight line - no special effects, connected, straight line
98+
$dataSeriesValues[1] // square fill
99+
->setPointMarker('square')
100+
->setPointSize(6)
101+
->getMarkerBorderColor()
102+
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
103+
$dataSeriesValues[1] // square border
104+
->getMarkerFillColor()
105+
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
106+
$dataSeriesValues[1]
107+
->setScatterLines(true)
108+
->setSmoothLine(false)
109+
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB);
110+
$dataSeriesValues[1]->setLineWidth(2.0);
111+
112+
// series 3 - markers, no line
113+
$dataSeriesValues[2] // triangle fill
114+
//->setPointMarker('triangle') // let Excel choose shape
115+
->setPointSize(7)
116+
->getMarkerFillColor()
117+
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
118+
$dataSeriesValues[2] // triangle border
119+
->getMarkerBorderColor()
120+
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
121+
$dataSeriesValues[2]->setScatterLines(false); // points not connected
122+
67123
// Added so that Xaxis shows dates instead of Excel-equivalent-year1900-numbers
68124
$xAxis = new Axis();
69125
//$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE );
70126
$xAxis->setAxisNumberProperties(Properties::FORMAT_CODE_DATE_ISO8601, true);
71127

128+
$yAxis = new Axis();
129+
$yAxis->setLineStyleProperties(
130+
2.5, // width in points
131+
Properties::LINE_STYLE_COMPOUND_SIMPLE,
132+
Properties::LINE_STYLE_DASH_DASH_DOT,
133+
Properties::LINE_STYLE_CAP_FLAT,
134+
Properties::LINE_STYLE_JOIN_BEVEL
135+
);
136+
$yAxis->setLineColorProperties('ffc000', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
137+
72138
// Build the dataseries
73139
$series = new DataSeries(
74140
DataSeries::TYPE_SCATTERCHART, // plotType
@@ -79,8 +145,7 @@
79145
$dataSeriesValues, // plotValues
80146
null, // plotDirection
81147
false, // smooth line
82-
//DataSeries::STYLE_LINEMARKER // plotStyle
83-
DataSeries::STYLE_MARKER // plotStyle
148+
DataSeries::STYLE_SMOOTHMARKER // plotStyle
84149
);
85150

86151
// Set the series in the plot area
@@ -103,6 +168,7 @@
103168
$yAxisLabel, // yAxisLabel
104169
// added xAxis for correct date display
105170
$xAxis, // xAxis
171+
$yAxis, // yAxis
106172
);
107173

108174
// Set the position where the chart should appear in the worksheet
12.1 KB
Binary file not shown.

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4834,7 +4834,7 @@ private function processTokenStack($tokens, $cellID = null, ?Cell $cell = null)
48344834
$cell->attach($pCellParent);
48354835
} else {
48364836
$cellRef = ($cellSheet !== null) ? "'{$matches[2]}'!{$cellRef}" : $cellRef;
4837-
$cellValue = null;
4837+
$cellValue = ($cellSheet !== null) ? null : Information\ExcelError::REF();
48384838
}
48394839
} else {
48404840
return $this->raiseFormulaError('Unable to access Cell Reference');

src/PhpSpreadsheet/Calculation/Information/ExcelError.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ class ExcelError
2525
'spill' => '#SPILL!',
2626
];
2727

28+
/**
29+
* @param mixed $value
30+
*/
31+
public static function throwError($value): string
32+
{
33+
return in_array($value, self::$errorCodes, true) ? $value : self::$errorCodes['value'];
34+
}
35+
2836
/**
2937
* ERROR_TYPE.
3038
*

src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function validateNumericNullBool($number)
3838
return 0 + $number;
3939
}
4040

41-
throw new Exception(ExcelError::VALUE());
41+
throw new Exception(ExcelError::throwError($number));
4242
}
4343

4444
/**
@@ -59,7 +59,7 @@ public static function validateNumericNullSubstitution($number, $substitute)
5959
return 0 + $number;
6060
}
6161

62-
throw new Exception(ExcelError::VALUE());
62+
throw new Exception(ExcelError::throwError($number));
6363
}
6464

6565
/**

src/PhpSpreadsheet/Calculation/MathTrig/Operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function ($value) {
118118
if (is_numeric($arg)) {
119119
$returnValue *= $arg;
120120
} else {
121-
return ExcelError::VALUE();
121+
return ExcelError::throwError($arg);
122122
}
123123
}
124124

0 commit comments

Comments
 (0)