Skip to content

Commit 4706749

Browse files
authored
Merge branch 'master' into Calculation-Examples
2 parents 441ae74 + 8513c64 commit 4706749

File tree

68 files changed

+737
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+737
-525
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
8282
"dompdf/dompdf": "^1.0 || ^2.0",
8383
"friendsofphp/php-cs-fixer": "^3.2",
84-
"mitoteam/jpgraph": "^10.1",
84+
"mitoteam/jpgraph": "10.2.3",
8585
"mpdf/mpdf": "8.1.1",
8686
"phpcompatibility/php-compatibility": "^9.3",
8787
"phpstan/phpstan": "^1.1",

composer.lock

Lines changed: 13 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/DocumentGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private static function getCategories(): array
4141
private static function tableRow(array $lengths, ?array $values = null): string
4242
{
4343
$result = '';
44-
foreach (array_map(null, $lengths, $values ?? []) as $i => [$length, $value]) {
44+
foreach (array_map(/** @scrutinizer ignore-type */ null, $lengths, $values ?? []) as $i => [$length, $value]) {
4545
$pad = $value === null ? '-' : ' ';
4646
if ($i > 0) {
4747
$result .= '|' . $pad;

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2590,21 +2590,6 @@ parameters:
25902590
count: 1
25912591
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
25922592

2593-
-
2594-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:setFirstPageNumber\\(\\) expects int, null given\\.$#"
2595-
count: 1
2596-
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
2597-
2598-
-
2599-
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:\\$pageOrder has no type specified\\.$#"
2600-
count: 1
2601-
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
2602-
2603-
-
2604-
message: "#^Strict comparison using \\=\\=\\= between int\\<min, \\-1\\> and null will always evaluate to false\\.$#"
2605-
count: 1
2606-
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
2607-
26082593
-
26092594
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\SheetView\\:\\:\\$sheetViewTypes has no type specified\\.$#"
26102595
count: 1

samples/Basic/49_alignment.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
use PhpOffice\PhpSpreadsheet\Spreadsheet;
4+
use PhpOffice\PhpSpreadsheet\Style\Alignment;
5+
6+
require __DIR__ . '/../Header.php';
7+
8+
$helper->log('Create new Spreadsheet object');
9+
$spreadsheet = new Spreadsheet();
10+
$spreadsheet->getProperties()->setTitle('Alignment');
11+
$sheet = $spreadsheet->getActiveSheet();
12+
$hi = 'Hi There';
13+
$ju = 'This is a longer than normal sentence';
14+
$sheet->fromArray([
15+
['', 'default', 'bottom', 'top', 'center', 'justify', 'distributed'],
16+
['default', $hi, $hi, $hi, $hi, $hi, $hi],
17+
['left', $hi, $hi, $hi, $hi, $hi, $hi],
18+
['right', $hi, $hi, $hi, $hi, $hi, $hi],
19+
['center', $hi, $hi, $hi, $hi, $hi, $hi],
20+
['justify', $ju, $ju, $ju, $ju, $ju, $ju],
21+
['distributed', $ju, $ju, $ju, $ju, $ju, $ju],
22+
]);
23+
$sheet->getColumnDimension('B')->setWidth(20);
24+
$sheet->getColumnDimension('C')->setWidth(20);
25+
$sheet->getColumnDimension('D')->setWidth(20);
26+
$sheet->getColumnDimension('E')->setWidth(20);
27+
$sheet->getColumnDimension('F')->setWidth(20);
28+
$sheet->getColumnDimension('G')->setWidth(20);
29+
$sheet->getRowDimension(2)->setRowHeight(30);
30+
$sheet->getRowDimension(3)->setRowHeight(30);
31+
$sheet->getRowDimension(4)->setRowHeight(30);
32+
$sheet->getRowDimension(5)->setRowHeight(30);
33+
$sheet->getRowDimension(6)->setRowHeight(40);
34+
$sheet->getRowDimension(7)->setRowHeight(40);
35+
$minRow = 2;
36+
$maxRow = 7;
37+
$minCol = 'B';
38+
$maxCol = 'g';
39+
$sheet->getStyle("C$minRow:C$maxRow")
40+
->getAlignment()
41+
->setVertical(Alignment::VERTICAL_BOTTOM);
42+
$sheet->getStyle("D$minRow:D$maxRow")
43+
->getAlignment()
44+
->setVertical(Alignment::VERTICAL_TOP);
45+
$sheet->getStyle("E$minRow:E$maxRow")
46+
->getAlignment()
47+
->setVertical(Alignment::VERTICAL_CENTER);
48+
$sheet->getStyle("F$minRow:F$maxRow")
49+
->getAlignment()
50+
->setVertical(Alignment::VERTICAL_JUSTIFY);
51+
$sheet->getStyle("G$minRow:G$maxRow")
52+
->getAlignment()
53+
->setVertical(Alignment::VERTICAL_DISTRIBUTED);
54+
$sheet->getStyle("{$minCol}3:{$maxCol}3")
55+
->getAlignment()
56+
->setHorizontal(Alignment::HORIZONTAL_LEFT);
57+
$sheet->getStyle("{$minCol}4:{$maxCol}4")
58+
->getAlignment()
59+
->setHorizontal(Alignment::HORIZONTAL_RIGHT);
60+
$sheet->getStyle("{$minCol}5:{$maxCol}5")
61+
->getAlignment()
62+
->setHorizontal(Alignment::HORIZONTAL_CENTER);
63+
$sheet->getStyle("{$minCol}6:{$maxCol}6")
64+
->getAlignment()
65+
->setHorizontal(Alignment::HORIZONTAL_JUSTIFY);
66+
$sheet->getStyle("{$minCol}7:{$maxCol}7")
67+
->getAlignment()
68+
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED);
69+
70+
$sheet->getCell('A9')->setValue('Center Continuous A9-C9');
71+
$sheet->getStyle('A9:C9')
72+
->getAlignment()
73+
->setHorizontal(Alignment::HORIZONTAL_CENTER_CONTINUOUS);
74+
$sheet->getCell('A10')->setValue('Fill');
75+
$sheet->getStyle('A10')
76+
->getAlignment()
77+
->setHorizontal(Alignment::HORIZONTAL_FILL);
78+
$sheet->setSelectedCells('A1');
79+
80+
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Html', 'Xls']);

samples/Chart/33_Chart_create_line_dateaxis.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@
101101
// marker details
102102
$dataSeriesValues[0]
103103
->getMarkerFillColor()
104-
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
104+
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
105105
$dataSeriesValues[0]
106106
->getMarkerBorderColor()
107-
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
107+
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
108108

109109
// line details - dashed, smooth line (Bezier) with arrows, 40% transparent
110110
$dataSeriesValues[0]
@@ -129,18 +129,18 @@
129129
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
130130
$dataSeriesValues[1] // square marker fill color
131131
->getMarkerFillColor()
132-
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
132+
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
133133
$dataSeriesValues[1]
134134
->setScatterLines(true)
135135
->setSmoothLine(false)
136-
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_ARGB);
136+
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB);
137137
$dataSeriesValues[1]->setLineWidth(2.0);
138138

139139
// series 3 - metric3, markers, no line
140140
$dataSeriesValues[2] // triangle? fill
141141
//->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle
142142
->getMarkerFillColor()
143-
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
143+
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
144144
$dataSeriesValues[2] // triangle border
145145
->getMarkerBorderColor()
146146
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
@@ -239,7 +239,7 @@
239239
->setScatterlines(false); // disable connecting lines
240240
$dataSeriesValues[0]
241241
->getMarkerFillColor()
242-
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
242+
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
243243
$dataSeriesValues[0]
244244
->getMarkerBorderColor()
245245
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
@@ -326,7 +326,7 @@
326326
// Set the position of the chart in the chart sheet below the first chart
327327
$chart->setTopLeftPosition('A13');
328328
$chart->setBottomRightPosition('P25');
329-
$chart->setRoundedCorners('true'); // Rounded corners in Chart Outline
329+
$chart->setRoundedCorners(true); // Rounded corners in Chart Outline
330330

331331
// Add the chart to the worksheet $chartSheet
332332
$chartSheet->addChart($chart);
@@ -350,8 +350,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
350350
$startDate = DateTime::createFromFormat('Y-m-d', $startDateStr); // php date obj
351351

352352
// get date of first day of the quarter of the start date
353-
$startMonth = $startDate->format('n'); // suppress leading zero
354-
$startYr = $startDate->format('Y');
353+
$startMonth = (int) $startDate->format('n'); // suppress leading zero
354+
$startYr = (int) $startDate->format('Y');
355355
$qtr = intdiv($startMonth, 3) + (($startMonth % 3 > 0) ? 1 : 0);
356356
$qtrStartMonth = sprintf('%02d', 1 + (($qtr - 1) * 3));
357357
$qtrStartStr = "$startYr-$qtrStartMonth-01";
@@ -360,8 +360,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
360360
// end the xaxis at the end of the quarter of the last date
361361
$lastDateStr = $dataSheet->getCellByColumnAndRow(2, $nrows + 1)->getValue();
362362
$lastDate = DateTime::createFromFormat('Y-m-d', $lastDateStr);
363-
$lastMonth = $lastDate->format('n');
364-
$lastYr = $lastDate->format('Y');
363+
$lastMonth = (int) $lastDate->format('n');
364+
$lastYr = (int) $lastDate->format('Y');
365365
$qtr = intdiv($lastMonth, 3) + (($lastMonth % 3 > 0) ? 1 : 0);
366366
$qtrEndMonth = 3 + (($qtr - 1) * 3);
367367
$lastDOM = cal_days_in_month(CAL_GREGORIAN, $qtrEndMonth, $lastYr);

samples/Chart/35_Chart_render.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
$unresolvedErrors = [];
2626
} else {
2727
$unresolvedErrors = [
28+
// The following spreadsheet was created by 3rd party software,
29+
// and doesn't include the data that usually accompanies a chart.
30+
// That is good enough for Excel, but not for JpGraph.
2831
'32readwriteBubbleChart2.xlsx',
29-
'32readwritePieChart3.xlsx',
30-
'32readwritePieChart4.xlsx',
31-
'32readwritePieChart3D1.xlsx',
32-
'32readwritePieChartExploded1.xlsx',
33-
'32readwritePieChartExploded3D1.xlsx',
3432
];
3533
}
3634
foreach ($inputFileNames as $inputFileName) {
@@ -42,7 +40,9 @@
4240
continue;
4341
}
4442
if (in_array($inputFileNameShort, $unresolvedErrors, true)) {
45-
$helper->log('File ' . $inputFileNameShort . ' does not yet work with this script');
43+
$helper->log('*****');
44+
$helper->log('***** File ' . $inputFileNameShort . ' does not yet work with this script');
45+
$helper->log('*****');
4646

4747
continue;
4848
}
@@ -92,6 +92,7 @@
9292

9393
$spreadsheet->disconnectWorksheets();
9494
unset($spreadsheet);
95+
gc_collect_cycles();
9596
}
9697

9798
$helper->log('Done rendering charts as images');

samples/Reader/16_Handling_loader_exceptions_using_TryCatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
try {
1212
$spreadsheet = IOFactory::load($inputFileName);
1313
} catch (ReaderException $e) {
14-
$helper->log('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
14+
$helper->log('Error loading file "' . /** @scrutinizer ignore-type */ pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
1515
}

src/PhpSpreadsheet/Chart/Axis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public function setAxisType(string $type): self
219219
* @param ?int $alpha
220220
* @param ?string $AlphaType
221221
*/
222-
public function setFillParameters($color, $alpha = null, $AlphaType = self::EXCEL_COLOR_TYPE_ARGB): void
222+
public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
223223
{
224224
$this->fillColor->setColorProperties($color, $alpha, $AlphaType);
225225
}

src/PhpSpreadsheet/Chart/Chart.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,11 @@ public function getRoundedCorners(): bool
774774
return $this->roundedCorners;
775775
}
776776

777-
public function setRoundedCorners(bool $roundedCorners): self
777+
public function setRoundedCorners(?bool $roundedCorners): self
778778
{
779-
$this->roundedCorners = $roundedCorners;
779+
if ($roundedCorners !== null) {
780+
$this->roundedCorners = $roundedCorners;
781+
}
780782

781783
return $this;
782784
}

0 commit comments

Comments
 (0)