Merge branch 'master' into Calculation-Examples
This commit is contained in:
commit
47067494f5
|
|
@ -81,7 +81,7 @@
|
||||||
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
"dealerdirect/phpcodesniffer-composer-installer": "dev-master",
|
||||||
"dompdf/dompdf": "^1.0 || ^2.0",
|
"dompdf/dompdf": "^1.0 || ^2.0",
|
||||||
"friendsofphp/php-cs-fixer": "^3.2",
|
"friendsofphp/php-cs-fixer": "^3.2",
|
||||||
"mitoteam/jpgraph": "^10.1",
|
"mitoteam/jpgraph": "10.2.3",
|
||||||
"mpdf/mpdf": "8.1.1",
|
"mpdf/mpdf": "8.1.1",
|
||||||
"phpcompatibility/php-compatibility": "^9.3",
|
"phpcompatibility/php-compatibility": "^9.3",
|
||||||
"phpstan/phpstan": "^1.1",
|
"phpstan/phpstan": "^1.1",
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "dd19bb54ddc39f5b24f564818cb46c7e",
|
"content-hash": "b5bdb9f96d18ce59557436521053fdd9",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "ezyang/htmlpurifier",
|
"name": "ezyang/htmlpurifier",
|
||||||
|
|
@ -1342,20 +1342,23 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mitoteam/jpgraph",
|
"name": "mitoteam/jpgraph",
|
||||||
"version": "10.1.3",
|
"version": "10.2.3",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/mitoteam/jpgraph.git",
|
"url": "https://github.com/mitoteam/jpgraph.git",
|
||||||
"reference": "425a2a0f0c97a28fe0aca60a4384ce85880e438a"
|
"reference": "21121535537e05c32e7964327b80746462a6057d"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/mitoteam/jpgraph/zipball/425a2a0f0c97a28fe0aca60a4384ce85880e438a",
|
"url": "https://api.github.com/repos/mitoteam/jpgraph/zipball/21121535537e05c32e7964327b80746462a6057d",
|
||||||
"reference": "425a2a0f0c97a28fe0aca60a4384ce85880e438a",
|
"reference": "21121535537e05c32e7964327b80746462a6057d",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.5"
|
"php": ">=5.5 <=8.2"
|
||||||
|
},
|
||||||
|
"replace": {
|
||||||
|
"jpgraph/jpgraph": "4.0.2"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|
@ -1372,16 +1375,16 @@
|
||||||
"name": "JpGraph team"
|
"name": "JpGraph team"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Composer compatible version of JpGraph library with PHP 8.1 support",
|
"description": "JpGraph library composer package with PHP 8.2 support",
|
||||||
"homepage": "https://github.com/mitoteam/jpgraph",
|
"homepage": "https://github.com/mitoteam/jpgraph",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"jpgraph"
|
"jpgraph"
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/mitoteam/jpgraph/issues",
|
"issues": "https://github.com/mitoteam/jpgraph/issues",
|
||||||
"source": "https://github.com/mitoteam/jpgraph/tree/10.1.3"
|
"source": "https://github.com/mitoteam/jpgraph/tree/10.2.3"
|
||||||
},
|
},
|
||||||
"time": "2022-07-05T16:46:34+00:00"
|
"time": "2022-09-14T04:02:09+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "mpdf/mpdf",
|
"name": "mpdf/mpdf",
|
||||||
|
|
@ -5265,5 +5268,5 @@
|
||||||
"ext-zlib": "*"
|
"ext-zlib": "*"
|
||||||
},
|
},
|
||||||
"platform-dev": [],
|
"platform-dev": [],
|
||||||
"plugin-api-version": "2.3.0"
|
"plugin-api-version": "2.2.0"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class DocumentGenerator
|
||||||
private static function tableRow(array $lengths, ?array $values = null): string
|
private static function tableRow(array $lengths, ?array $values = null): string
|
||||||
{
|
{
|
||||||
$result = '';
|
$result = '';
|
||||||
foreach (array_map(null, $lengths, $values ?? []) as $i => [$length, $value]) {
|
foreach (array_map(/** @scrutinizer ignore-type */ null, $lengths, $values ?? []) as $i => [$length, $value]) {
|
||||||
$pad = $value === null ? '-' : ' ';
|
$pad = $value === null ? '-' : ' ';
|
||||||
if ($i > 0) {
|
if ($i > 0) {
|
||||||
$result .= '|' . $pad;
|
$result .= '|' . $pad;
|
||||||
|
|
|
||||||
|
|
@ -2590,21 +2590,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
|
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:setFirstPageNumber\\(\\) expects int, null given\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\PageSetup\\:\\:\\$pageOrder has no type specified\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
|
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Strict comparison using \\=\\=\\= between int\\<min, \\-1\\> and null will always evaluate to false\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: src/PhpSpreadsheet/Worksheet/PageSetup.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\SheetView\\:\\:\\$sheetViewTypes has no type specified\\.$#"
|
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\SheetView\\:\\:\\$sheetViewTypes has no type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
|
|
||||||
|
require __DIR__ . '/../Header.php';
|
||||||
|
|
||||||
|
$helper->log('Create new Spreadsheet object');
|
||||||
|
$spreadsheet = new Spreadsheet();
|
||||||
|
$spreadsheet->getProperties()->setTitle('Alignment');
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
$hi = 'Hi There';
|
||||||
|
$ju = 'This is a longer than normal sentence';
|
||||||
|
$sheet->fromArray([
|
||||||
|
['', 'default', 'bottom', 'top', 'center', 'justify', 'distributed'],
|
||||||
|
['default', $hi, $hi, $hi, $hi, $hi, $hi],
|
||||||
|
['left', $hi, $hi, $hi, $hi, $hi, $hi],
|
||||||
|
['right', $hi, $hi, $hi, $hi, $hi, $hi],
|
||||||
|
['center', $hi, $hi, $hi, $hi, $hi, $hi],
|
||||||
|
['justify', $ju, $ju, $ju, $ju, $ju, $ju],
|
||||||
|
['distributed', $ju, $ju, $ju, $ju, $ju, $ju],
|
||||||
|
]);
|
||||||
|
$sheet->getColumnDimension('B')->setWidth(20);
|
||||||
|
$sheet->getColumnDimension('C')->setWidth(20);
|
||||||
|
$sheet->getColumnDimension('D')->setWidth(20);
|
||||||
|
$sheet->getColumnDimension('E')->setWidth(20);
|
||||||
|
$sheet->getColumnDimension('F')->setWidth(20);
|
||||||
|
$sheet->getColumnDimension('G')->setWidth(20);
|
||||||
|
$sheet->getRowDimension(2)->setRowHeight(30);
|
||||||
|
$sheet->getRowDimension(3)->setRowHeight(30);
|
||||||
|
$sheet->getRowDimension(4)->setRowHeight(30);
|
||||||
|
$sheet->getRowDimension(5)->setRowHeight(30);
|
||||||
|
$sheet->getRowDimension(6)->setRowHeight(40);
|
||||||
|
$sheet->getRowDimension(7)->setRowHeight(40);
|
||||||
|
$minRow = 2;
|
||||||
|
$maxRow = 7;
|
||||||
|
$minCol = 'B';
|
||||||
|
$maxCol = 'g';
|
||||||
|
$sheet->getStyle("C$minRow:C$maxRow")
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_BOTTOM);
|
||||||
|
$sheet->getStyle("D$minRow:D$maxRow")
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_TOP);
|
||||||
|
$sheet->getStyle("E$minRow:E$maxRow")
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_CENTER);
|
||||||
|
$sheet->getStyle("F$minRow:F$maxRow")
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_JUSTIFY);
|
||||||
|
$sheet->getStyle("G$minRow:G$maxRow")
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_DISTRIBUTED);
|
||||||
|
$sheet->getStyle("{$minCol}3:{$maxCol}3")
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_LEFT);
|
||||||
|
$sheet->getStyle("{$minCol}4:{$maxCol}4")
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_RIGHT);
|
||||||
|
$sheet->getStyle("{$minCol}5:{$maxCol}5")
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_CENTER);
|
||||||
|
$sheet->getStyle("{$minCol}6:{$maxCol}6")
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_JUSTIFY);
|
||||||
|
$sheet->getStyle("{$minCol}7:{$maxCol}7")
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_DISTRIBUTED);
|
||||||
|
|
||||||
|
$sheet->getCell('A9')->setValue('Center Continuous A9-C9');
|
||||||
|
$sheet->getStyle('A9:C9')
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_CENTER_CONTINUOUS);
|
||||||
|
$sheet->getCell('A10')->setValue('Fill');
|
||||||
|
$sheet->getStyle('A10')
|
||||||
|
->getAlignment()
|
||||||
|
->setHorizontal(Alignment::HORIZONTAL_FILL);
|
||||||
|
$sheet->setSelectedCells('A1');
|
||||||
|
|
||||||
|
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Html', 'Xls']);
|
||||||
|
|
@ -101,10 +101,10 @@ $dataSeriesValues = [
|
||||||
// marker details
|
// marker details
|
||||||
$dataSeriesValues[0]
|
$dataSeriesValues[0]
|
||||||
->getMarkerFillColor()
|
->getMarkerFillColor()
|
||||||
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
|
->setColorProperties('0070C0', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
|
||||||
$dataSeriesValues[0]
|
$dataSeriesValues[0]
|
||||||
->getMarkerBorderColor()
|
->getMarkerBorderColor()
|
||||||
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
|
->setColorProperties('002060', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
|
||||||
|
|
||||||
// line details - dashed, smooth line (Bezier) with arrows, 40% transparent
|
// line details - dashed, smooth line (Bezier) with arrows, 40% transparent
|
||||||
$dataSeriesValues[0]
|
$dataSeriesValues[0]
|
||||||
|
|
@ -129,18 +129,18 @@ $dataSeriesValues[1] // square marker border color
|
||||||
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
|
->setColorProperties('accent6', 3, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
|
||||||
$dataSeriesValues[1] // square marker fill color
|
$dataSeriesValues[1] // square marker fill color
|
||||||
->getMarkerFillColor()
|
->getMarkerFillColor()
|
||||||
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
|
->setColorProperties('0FFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
|
||||||
$dataSeriesValues[1]
|
$dataSeriesValues[1]
|
||||||
->setScatterLines(true)
|
->setScatterLines(true)
|
||||||
->setSmoothLine(false)
|
->setSmoothLine(false)
|
||||||
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_ARGB);
|
->setLineColorProperties('FF0000', 80, ChartColor::EXCEL_COLOR_TYPE_RGB);
|
||||||
$dataSeriesValues[1]->setLineWidth(2.0);
|
$dataSeriesValues[1]->setLineWidth(2.0);
|
||||||
|
|
||||||
// series 3 - metric3, markers, no line
|
// series 3 - metric3, markers, no line
|
||||||
$dataSeriesValues[2] // triangle? fill
|
$dataSeriesValues[2] // triangle? fill
|
||||||
//->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle
|
//->setPointMarker('triangle') // let Excel choose shape, which is predicted to be a triangle
|
||||||
->getMarkerFillColor()
|
->getMarkerFillColor()
|
||||||
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
|
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
|
||||||
$dataSeriesValues[2] // triangle border
|
$dataSeriesValues[2] // triangle border
|
||||||
->getMarkerBorderColor()
|
->getMarkerBorderColor()
|
||||||
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
|
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
|
||||||
|
|
@ -239,7 +239,7 @@ $dataSeriesValues[0]
|
||||||
->setScatterlines(false); // disable connecting lines
|
->setScatterlines(false); // disable connecting lines
|
||||||
$dataSeriesValues[0]
|
$dataSeriesValues[0]
|
||||||
->getMarkerFillColor()
|
->getMarkerFillColor()
|
||||||
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_ARGB);
|
->setColorProperties('FFFF00', null, ChartColor::EXCEL_COLOR_TYPE_RGB);
|
||||||
$dataSeriesValues[0]
|
$dataSeriesValues[0]
|
||||||
->getMarkerBorderColor()
|
->getMarkerBorderColor()
|
||||||
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
|
->setColorProperties('accent4', null, ChartColor::EXCEL_COLOR_TYPE_SCHEME);
|
||||||
|
|
@ -326,7 +326,7 @@ $chart = new Chart(
|
||||||
// Set the position of the chart in the chart sheet below the first chart
|
// Set the position of the chart in the chart sheet below the first chart
|
||||||
$chart->setTopLeftPosition('A13');
|
$chart->setTopLeftPosition('A13');
|
||||||
$chart->setBottomRightPosition('P25');
|
$chart->setBottomRightPosition('P25');
|
||||||
$chart->setRoundedCorners('true'); // Rounded corners in Chart Outline
|
$chart->setRoundedCorners(true); // Rounded corners in Chart Outline
|
||||||
|
|
||||||
// Add the chart to the worksheet $chartSheet
|
// Add the chart to the worksheet $chartSheet
|
||||||
$chartSheet->addChart($chart);
|
$chartSheet->addChart($chart);
|
||||||
|
|
@ -350,8 +350,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
|
||||||
$startDate = DateTime::createFromFormat('Y-m-d', $startDateStr); // php date obj
|
$startDate = DateTime::createFromFormat('Y-m-d', $startDateStr); // php date obj
|
||||||
|
|
||||||
// get date of first day of the quarter of the start date
|
// get date of first day of the quarter of the start date
|
||||||
$startMonth = $startDate->format('n'); // suppress leading zero
|
$startMonth = (int) $startDate->format('n'); // suppress leading zero
|
||||||
$startYr = $startDate->format('Y');
|
$startYr = (int) $startDate->format('Y');
|
||||||
$qtr = intdiv($startMonth, 3) + (($startMonth % 3 > 0) ? 1 : 0);
|
$qtr = intdiv($startMonth, 3) + (($startMonth % 3 > 0) ? 1 : 0);
|
||||||
$qtrStartMonth = sprintf('%02d', 1 + (($qtr - 1) * 3));
|
$qtrStartMonth = sprintf('%02d', 1 + (($qtr - 1) * 3));
|
||||||
$qtrStartStr = "$startYr-$qtrStartMonth-01";
|
$qtrStartStr = "$startYr-$qtrStartMonth-01";
|
||||||
|
|
@ -360,8 +360,8 @@ function dateRange(int $nrows, Spreadsheet $wrkbk): array
|
||||||
// end the xaxis at the end of the quarter of the last date
|
// end the xaxis at the end of the quarter of the last date
|
||||||
$lastDateStr = $dataSheet->getCellByColumnAndRow(2, $nrows + 1)->getValue();
|
$lastDateStr = $dataSheet->getCellByColumnAndRow(2, $nrows + 1)->getValue();
|
||||||
$lastDate = DateTime::createFromFormat('Y-m-d', $lastDateStr);
|
$lastDate = DateTime::createFromFormat('Y-m-d', $lastDateStr);
|
||||||
$lastMonth = $lastDate->format('n');
|
$lastMonth = (int) $lastDate->format('n');
|
||||||
$lastYr = $lastDate->format('Y');
|
$lastYr = (int) $lastDate->format('Y');
|
||||||
$qtr = intdiv($lastMonth, 3) + (($lastMonth % 3 > 0) ? 1 : 0);
|
$qtr = intdiv($lastMonth, 3) + (($lastMonth % 3 > 0) ? 1 : 0);
|
||||||
$qtrEndMonth = 3 + (($qtr - 1) * 3);
|
$qtrEndMonth = 3 + (($qtr - 1) * 3);
|
||||||
$lastDOM = cal_days_in_month(CAL_GREGORIAN, $qtrEndMonth, $lastYr);
|
$lastDOM = cal_days_in_month(CAL_GREGORIAN, $qtrEndMonth, $lastYr);
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,10 @@ if (count($inputFileNames) === 1) {
|
||||||
$unresolvedErrors = [];
|
$unresolvedErrors = [];
|
||||||
} else {
|
} else {
|
||||||
$unresolvedErrors = [
|
$unresolvedErrors = [
|
||||||
|
// The following spreadsheet was created by 3rd party software,
|
||||||
|
// and doesn't include the data that usually accompanies a chart.
|
||||||
|
// That is good enough for Excel, but not for JpGraph.
|
||||||
'32readwriteBubbleChart2.xlsx',
|
'32readwriteBubbleChart2.xlsx',
|
||||||
'32readwritePieChart3.xlsx',
|
|
||||||
'32readwritePieChart4.xlsx',
|
|
||||||
'32readwritePieChart3D1.xlsx',
|
|
||||||
'32readwritePieChartExploded1.xlsx',
|
|
||||||
'32readwritePieChartExploded3D1.xlsx',
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
foreach ($inputFileNames as $inputFileName) {
|
foreach ($inputFileNames as $inputFileName) {
|
||||||
|
|
@ -42,7 +40,9 @@ foreach ($inputFileNames as $inputFileName) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (in_array($inputFileNameShort, $unresolvedErrors, true)) {
|
if (in_array($inputFileNameShort, $unresolvedErrors, true)) {
|
||||||
$helper->log('File ' . $inputFileNameShort . ' does not yet work with this script');
|
$helper->log('*****');
|
||||||
|
$helper->log('***** File ' . $inputFileNameShort . ' does not yet work with this script');
|
||||||
|
$helper->log('*****');
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -92,6 +92,7 @@ foreach ($inputFileNames as $inputFileName) {
|
||||||
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
unset($spreadsheet);
|
unset($spreadsheet);
|
||||||
|
gc_collect_cycles();
|
||||||
}
|
}
|
||||||
|
|
||||||
$helper->log('Done rendering charts as images');
|
$helper->log('Done rendering charts as images');
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ $helper->log('Loading file ' . /** @scrutinizer ignore-type */ pathinfo($inputFi
|
||||||
try {
|
try {
|
||||||
$spreadsheet = IOFactory::load($inputFileName);
|
$spreadsheet = IOFactory::load($inputFileName);
|
||||||
} catch (ReaderException $e) {
|
} catch (ReaderException $e) {
|
||||||
$helper->log('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
$helper->log('Error loading file "' . /** @scrutinizer ignore-type */ pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -219,7 +219,7 @@ class Axis extends Properties
|
||||||
* @param ?int $alpha
|
* @param ?int $alpha
|
||||||
* @param ?string $AlphaType
|
* @param ?string $AlphaType
|
||||||
*/
|
*/
|
||||||
public function setFillParameters($color, $alpha = null, $AlphaType = self::EXCEL_COLOR_TYPE_ARGB): void
|
public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
|
||||||
{
|
{
|
||||||
$this->fillColor->setColorProperties($color, $alpha, $AlphaType);
|
$this->fillColor->setColorProperties($color, $alpha, $AlphaType);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -774,9 +774,11 @@ class Chart
|
||||||
return $this->roundedCorners;
|
return $this->roundedCorners;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRoundedCorners(bool $roundedCorners): self
|
public function setRoundedCorners(?bool $roundedCorners): self
|
||||||
{
|
{
|
||||||
$this->roundedCorners = $roundedCorners;
|
if ($roundedCorners !== null) {
|
||||||
|
$this->roundedCorners = $roundedCorners;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,13 +102,11 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
return $seriesPlot;
|
return $seriesPlot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation = '')
|
private function formatDataSetLabels($groupID, $datasetLabels, $rotation = '')
|
||||||
{
|
{
|
||||||
$datasetLabelFormatCode = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode();
|
$datasetLabelFormatCode = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getFormatCode() ?? '';
|
||||||
if ($datasetLabelFormatCode !== null) {
|
// Retrieve any label formatting code
|
||||||
// Retrieve any label formatting code
|
$datasetLabelFormatCode = stripslashes($datasetLabelFormatCode);
|
||||||
$datasetLabelFormatCode = stripslashes($datasetLabelFormatCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$testCurrentIndex = 0;
|
$testCurrentIndex = 0;
|
||||||
foreach ($datasetLabels as $i => $datasetLabel) {
|
foreach ($datasetLabels as $i => $datasetLabel) {
|
||||||
|
|
@ -273,7 +271,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$this->renderTitle();
|
$this->renderTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderPlotLine($groupID, $filled = false, $combination = false, $dimensions = '2d'): void
|
private function renderPlotLine($groupID, $filled = false, $combination = false): void
|
||||||
{
|
{
|
||||||
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
|
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
|
||||||
|
|
||||||
|
|
@ -281,7 +279,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointCount();
|
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointCount();
|
||||||
if ($labelCount > 0) {
|
if ($labelCount > 0) {
|
||||||
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
||||||
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $labelCount);
|
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels);
|
||||||
$this->graph->xaxis->SetTickLabels($datasetLabels);
|
$this->graph->xaxis->SetTickLabels($datasetLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,7 +351,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointCount();
|
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($index)->getPointCount();
|
||||||
if ($labelCount > 0) {
|
if ($labelCount > 0) {
|
||||||
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
||||||
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $labelCount, $rotation);
|
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $rotation);
|
||||||
// Rotate for bar rather than column chart
|
// Rotate for bar rather than column chart
|
||||||
if ($rotation == 'bar') {
|
if ($rotation == 'bar') {
|
||||||
$datasetLabels = array_reverse($datasetLabels);
|
$datasetLabels = array_reverse($datasetLabels);
|
||||||
|
|
@ -430,11 +428,9 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
|
|
||||||
private function renderPlotScatter($groupID, $bubble): void
|
private function renderPlotScatter($groupID, $bubble): void
|
||||||
{
|
{
|
||||||
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
|
|
||||||
$scatterStyle = $bubbleSize = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
$scatterStyle = $bubbleSize = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
||||||
|
|
||||||
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
||||||
$seriesPlots = [];
|
|
||||||
|
|
||||||
// Loop through each data series in turn
|
// Loop through each data series in turn
|
||||||
for ($i = 0; $i < $seriesCount; ++$i) {
|
for ($i = 0; $i < $seriesCount; ++$i) {
|
||||||
|
|
@ -478,7 +474,6 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$radarStyle = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
$radarStyle = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
||||||
|
|
||||||
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
||||||
$seriesPlots = [];
|
|
||||||
|
|
||||||
// Loop through each data series in turn
|
// Loop through each data series in turn
|
||||||
for ($i = 0; $i < $seriesCount; ++$i) {
|
for ($i = 0; $i < $seriesCount; ++$i) {
|
||||||
|
|
@ -513,15 +508,11 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
|
|
||||||
private function renderPlotContour($groupID): void
|
private function renderPlotContour($groupID): void
|
||||||
{
|
{
|
||||||
$contourStyle = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
|
||||||
|
|
||||||
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
||||||
$seriesPlots = [];
|
|
||||||
|
|
||||||
$dataValues = [];
|
$dataValues = [];
|
||||||
// Loop through each data series in turn
|
// Loop through each data series in turn
|
||||||
for ($i = 0; $i < $seriesCount; ++$i) {
|
for ($i = 0; $i < $seriesCount; ++$i) {
|
||||||
$dataValuesY = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex($i)->getDataValues();
|
|
||||||
$dataValuesX = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
|
$dataValuesX = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex($i)->getDataValues();
|
||||||
|
|
||||||
$dataValues[$i] = $dataValuesX;
|
$dataValues[$i] = $dataValuesX;
|
||||||
|
|
@ -565,7 +556,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount();
|
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount();
|
||||||
if ($labelCount > 0) {
|
if ($labelCount > 0) {
|
||||||
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
||||||
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $labelCount);
|
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels);
|
||||||
$this->graph->xaxis->SetTickLabels($datasetLabels);
|
$this->graph->xaxis->SetTickLabels($datasetLabels);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -575,21 +566,21 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$this->graph->Add($seriesPlot);
|
$this->graph->Add($seriesPlot);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderAreaChart($groupCount, $dimensions = '2d'): void
|
private function renderAreaChart($groupCount): void
|
||||||
{
|
{
|
||||||
$this->renderCartesianPlotArea();
|
$this->renderCartesianPlotArea();
|
||||||
|
|
||||||
for ($i = 0; $i < $groupCount; ++$i) {
|
for ($i = 0; $i < $groupCount; ++$i) {
|
||||||
$this->renderPlotLine($i, true, false, $dimensions);
|
$this->renderPlotLine($i, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderLineChart($groupCount, $dimensions = '2d'): void
|
private function renderLineChart($groupCount): void
|
||||||
{
|
{
|
||||||
$this->renderCartesianPlotArea();
|
$this->renderCartesianPlotArea();
|
||||||
|
|
||||||
for ($i = 0; $i < $groupCount; ++$i) {
|
for ($i = 0; $i < $groupCount; ++$i) {
|
||||||
$this->renderPlotLine($i, false, false, $dimensions);
|
$this->renderPlotLine($i, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -626,19 +617,17 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
|
|
||||||
$iLimit = ($multiplePlots) ? $groupCount : 1;
|
$iLimit = ($multiplePlots) ? $groupCount : 1;
|
||||||
for ($groupID = 0; $groupID < $iLimit; ++$groupID) {
|
for ($groupID = 0; $groupID < $iLimit; ++$groupID) {
|
||||||
$grouping = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotGrouping();
|
|
||||||
$exploded = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
$exploded = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotStyle();
|
||||||
$datasetLabels = [];
|
$datasetLabels = [];
|
||||||
if ($groupID == 0) {
|
if ($groupID == 0) {
|
||||||
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount();
|
$labelCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotValuesByIndex(0)->getPointCount();
|
||||||
if ($labelCount > 0) {
|
if ($labelCount > 0) {
|
||||||
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
$datasetLabels = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotCategoryByIndex(0)->getDataValues();
|
||||||
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels, $labelCount);
|
$datasetLabels = $this->formatDataSetLabels($groupID, $datasetLabels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
$seriesCount = $this->chart->getPlotArea()->getPlotGroupByIndex($groupID)->getPlotSeriesCount();
|
||||||
$seriesPlots = [];
|
|
||||||
// For pie charts, we only display the first series: doughnut charts generally display all series
|
// For pie charts, we only display the first series: doughnut charts generally display all series
|
||||||
$jLimit = ($multiplePlots) ? $seriesCount : 1;
|
$jLimit = ($multiplePlots) ? $seriesCount : 1;
|
||||||
// Loop through each data series in turn
|
// Loop through each data series in turn
|
||||||
|
|
@ -669,7 +658,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$seriesPlot->SetSize(($jLimit - $j) / ($jLimit * 4));
|
$seriesPlot->SetSize(($jLimit - $j) / ($jLimit * 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($doughnut) {
|
if ($doughnut && method_exists($seriesPlot, 'SetMidColor')) {
|
||||||
$seriesPlot->SetMidColor('white');
|
$seriesPlot->SetMidColor('white');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -710,7 +699,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderContourChart($groupCount, $dimensions): void
|
private function renderContourChart($groupCount): void
|
||||||
{
|
{
|
||||||
$this->renderCartesianPlotArea('intint');
|
$this->renderCartesianPlotArea('intint');
|
||||||
|
|
||||||
|
|
@ -719,7 +708,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderCombinationChart($groupCount, $dimensions, $outputDestination)
|
private function renderCombinationChart($groupCount, $outputDestination)
|
||||||
{
|
{
|
||||||
$this->renderCartesianPlotArea();
|
$this->renderCartesianPlotArea();
|
||||||
|
|
||||||
|
|
@ -728,10 +717,8 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$chartType = $this->chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
|
$chartType = $this->chart->getPlotArea()->getPlotGroupByIndex($i)->getPlotType();
|
||||||
switch ($chartType) {
|
switch ($chartType) {
|
||||||
case 'area3DChart':
|
case 'area3DChart':
|
||||||
$dimensions = '3d';
|
|
||||||
// no break
|
|
||||||
case 'areaChart':
|
case 'areaChart':
|
||||||
$this->renderPlotLine($i, true, true, $dimensions);
|
$this->renderPlotLine($i, true, true);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'bar3DChart':
|
case 'bar3DChart':
|
||||||
|
|
@ -742,10 +729,8 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'line3DChart':
|
case 'line3DChart':
|
||||||
$dimensions = '3d';
|
|
||||||
// no break
|
|
||||||
case 'lineChart':
|
case 'lineChart':
|
||||||
$this->renderPlotLine($i, false, true, $dimensions);
|
$this->renderPlotLine($i, false, true);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'scatterChart':
|
case 'scatterChart':
|
||||||
|
|
@ -792,7 +777,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return $this->renderCombinationChart($groupCount, $dimensions, $outputDestination);
|
return $this->renderCombinationChart($groupCount, $outputDestination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -801,7 +786,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$dimensions = '3d';
|
$dimensions = '3d';
|
||||||
// no break
|
// no break
|
||||||
case 'areaChart':
|
case 'areaChart':
|
||||||
$this->renderAreaChart($groupCount, $dimensions);
|
$this->renderAreaChart($groupCount);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'bar3DChart':
|
case 'bar3DChart':
|
||||||
|
|
@ -815,7 +800,7 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
$dimensions = '3d';
|
$dimensions = '3d';
|
||||||
// no break
|
// no break
|
||||||
case 'lineChart':
|
case 'lineChart':
|
||||||
$this->renderLineChart($groupCount, $dimensions);
|
$this->renderLineChart($groupCount);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'pie3DChart':
|
case 'pie3DChart':
|
||||||
|
|
@ -845,10 +830,8 @@ abstract class JpGraphRendererBase implements IRenderer
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'surface3DChart':
|
case 'surface3DChart':
|
||||||
$dimensions = '3d';
|
|
||||||
// no break
|
|
||||||
case 'surfaceChart':
|
case 'surfaceChart':
|
||||||
$this->renderContourChart($groupCount, $dimensions);
|
$this->renderContourChart($groupCount);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'stockChart':
|
case 'stockChart':
|
||||||
|
|
|
||||||
|
|
@ -306,22 +306,25 @@ class Xlsx extends BaseReader
|
||||||
return (bool) $c->v;
|
return (bool) $c->v;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function castToError(SimpleXMLElement $c): ?string
|
private static function castToError(?SimpleXMLElement $c): ?string
|
||||||
{
|
{
|
||||||
return isset($c->v) ? (string) $c->v : null;
|
return isset($c, $c->v) ? (string) $c->v : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function castToString(SimpleXMLElement $c): ?string
|
private static function castToString(?SimpleXMLElement $c): ?string
|
||||||
{
|
{
|
||||||
return isset($c->v) ? (string) $c->v : null;
|
return isset($c, $c->v) ? (string) $c->v : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param mixed $calculatedValue
|
* @param mixed $calculatedValue
|
||||||
*/
|
*/
|
||||||
private function castToFormula(SimpleXMLElement $c, string $r, string &$cellDataType, &$value, &$calculatedValue, array &$sharedFormulas, string $castBaseType): void
|
private function castToFormula(?SimpleXMLElement $c, string $r, string &$cellDataType, &$value, &$calculatedValue, array &$sharedFormulas, string $castBaseType): void
|
||||||
{
|
{
|
||||||
|
if ($c === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$attr = $c->f->attributes();
|
$attr = $c->f->attributes();
|
||||||
$cellDataType = 'f';
|
$cellDataType = 'f';
|
||||||
$value = "={$c->f}";
|
$value = "={$c->f}";
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,9 @@ class AutoFilter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readCustomAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
|
private function readCustomAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
|
||||||
{
|
{
|
||||||
if ($filterColumn->customFilters) {
|
if (isset($filterColumn, $filterColumn->customFilters)) {
|
||||||
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER);
|
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER);
|
||||||
$customFilters = $filterColumn->customFilters;
|
$customFilters = $filterColumn->customFilters;
|
||||||
// Custom filters can an AND or an OR join;
|
// Custom filters can an AND or an OR join;
|
||||||
|
|
@ -104,9 +104,9 @@ class AutoFilter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readDynamicAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
|
private function readDynamicAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
|
||||||
{
|
{
|
||||||
if ($filterColumn->dynamicFilter) {
|
if (isset($filterColumn, $filterColumn->dynamicFilter)) {
|
||||||
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
|
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
|
||||||
// We should only ever have one dynamic filter
|
// We should only ever have one dynamic filter
|
||||||
foreach ($filterColumn->dynamicFilter as $filterRule) {
|
foreach ($filterColumn->dynamicFilter as $filterRule) {
|
||||||
|
|
@ -126,9 +126,9 @@ class AutoFilter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readTopTenAutoFilter(SimpleXMLElement $filterColumn, Column $column): void
|
private function readTopTenAutoFilter(?SimpleXMLElement $filterColumn, Column $column): void
|
||||||
{
|
{
|
||||||
if ($filterColumn->top10) {
|
if (isset($filterColumn, $filterColumn->top10)) {
|
||||||
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER);
|
$column->setFilterType(Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER);
|
||||||
// We should only ever have one top10 filter
|
// We should only ever have one top10 filter
|
||||||
foreach ($filterColumn->top10 as $filterRule) {
|
foreach ($filterColumn->top10 as $filterRule) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use PhpOffice\PhpSpreadsheet\Chart\GridLines;
|
||||||
use PhpOffice\PhpSpreadsheet\Chart\Layout;
|
use PhpOffice\PhpSpreadsheet\Chart\Layout;
|
||||||
use PhpOffice\PhpSpreadsheet\Chart\Legend;
|
use PhpOffice\PhpSpreadsheet\Chart\Legend;
|
||||||
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
|
use PhpOffice\PhpSpreadsheet\Chart\PlotArea;
|
||||||
use PhpOffice\PhpSpreadsheet\Chart\Properties;
|
use PhpOffice\PhpSpreadsheet\Chart\Properties as ChartProperties;
|
||||||
use PhpOffice\PhpSpreadsheet\Chart\Title;
|
use PhpOffice\PhpSpreadsheet\Chart\Title;
|
||||||
use PhpOffice\PhpSpreadsheet\Chart\TrendLine;
|
use PhpOffice\PhpSpreadsheet\Chart\TrendLine;
|
||||||
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
use PhpOffice\PhpSpreadsheet\RichText\RichText;
|
||||||
|
|
@ -113,6 +113,7 @@ class Chart
|
||||||
$plotSeries = $plotAttributes = [];
|
$plotSeries = $plotAttributes = [];
|
||||||
$catAxRead = false;
|
$catAxRead = false;
|
||||||
$plotNoFill = false;
|
$plotNoFill = false;
|
||||||
|
/** @var SimpleXMLElement $chartDetail */
|
||||||
foreach ($chartDetails as $chartDetailKey => $chartDetail) {
|
foreach ($chartDetails as $chartDetailKey => $chartDetail) {
|
||||||
switch ($chartDetailKey) {
|
switch ($chartDetailKey) {
|
||||||
case 'spPr':
|
case 'spPr':
|
||||||
|
|
@ -121,17 +122,18 @@ class Chart
|
||||||
$plotNoFill = true;
|
$plotNoFill = true;
|
||||||
}
|
}
|
||||||
if (isset($possibleNoFill->gradFill->gsLst)) {
|
if (isset($possibleNoFill->gradFill->gsLst)) {
|
||||||
|
/** @var SimpleXMLElement $gradient */
|
||||||
foreach ($possibleNoFill->gradFill->gsLst->gs as $gradient) {
|
foreach ($possibleNoFill->gradFill->gsLst->gs as $gradient) {
|
||||||
/** @var float */
|
/** @var float */
|
||||||
$pos = self::getAttribute($gradient, 'pos', 'float');
|
$pos = self::getAttribute($gradient, 'pos', 'float');
|
||||||
$gradientArray[] = [
|
$gradientArray[] = [
|
||||||
$pos / Properties::PERCENTAGE_MULTIPLIER,
|
$pos / ChartProperties::PERCENTAGE_MULTIPLIER,
|
||||||
new ChartColor($this->readColor($gradient)),
|
new ChartColor($this->readColor($gradient)),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isset($possibleNoFill->gradFill->lin)) {
|
if (isset($possibleNoFill->gradFill->lin)) {
|
||||||
$gradientLin = Properties::XmlToAngle((string) self::getAttribute($possibleNoFill->gradFill->lin, 'ang', 'string'));
|
$gradientLin = ChartProperties::XmlToAngle((string) self::getAttribute($possibleNoFill->gradFill->lin, 'ang', 'string'));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -464,12 +466,13 @@ class Chart
|
||||||
$pointSize = null;
|
$pointSize = null;
|
||||||
$noFill = false;
|
$noFill = false;
|
||||||
$bubble3D = false;
|
$bubble3D = false;
|
||||||
$dPtColors = [];
|
$dptColors = [];
|
||||||
$markerFillColor = null;
|
$markerFillColor = null;
|
||||||
$markerBorderColor = null;
|
$markerBorderColor = null;
|
||||||
$lineStyle = null;
|
$lineStyle = null;
|
||||||
$labelLayout = null;
|
$labelLayout = null;
|
||||||
$trendLines = [];
|
$trendLines = [];
|
||||||
|
/** @var SimpleXMLElement $seriesDetail */
|
||||||
foreach ($seriesDetails as $seriesKey => $seriesDetail) {
|
foreach ($seriesDetails as $seriesKey => $seriesDetail) {
|
||||||
switch ($seriesKey) {
|
switch ($seriesKey) {
|
||||||
case 'idx':
|
case 'idx':
|
||||||
|
|
@ -487,7 +490,6 @@ class Chart
|
||||||
break;
|
break;
|
||||||
case 'spPr':
|
case 'spPr':
|
||||||
$children = $seriesDetail->children($this->aNamespace);
|
$children = $seriesDetail->children($this->aNamespace);
|
||||||
$ln = $children->ln;
|
|
||||||
if (isset($children->ln)) {
|
if (isset($children->ln)) {
|
||||||
$ln = $children->ln;
|
$ln = $children->ln;
|
||||||
if (is_countable($ln->noFill) && count($ln->noFill) === 1) {
|
if (is_countable($ln->noFill) && count($ln->noFill) === 1) {
|
||||||
|
|
@ -1161,7 +1163,7 @@ class Chart
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readEffects(SimpleXMLElement $chartDetail, ?Properties $chartObject): void
|
private function readEffects(SimpleXMLElement $chartDetail, ?ChartProperties $chartObject): void
|
||||||
{
|
{
|
||||||
if (!isset($chartObject, $chartDetail->spPr)) {
|
if (!isset($chartObject, $chartDetail->spPr)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1169,7 +1171,7 @@ class Chart
|
||||||
$sppr = $chartDetail->spPr->children($this->aNamespace);
|
$sppr = $chartDetail->spPr->children($this->aNamespace);
|
||||||
|
|
||||||
if (isset($sppr->effectLst->glow)) {
|
if (isset($sppr->effectLst->glow)) {
|
||||||
$axisGlowSize = (float) self::getAttribute($sppr->effectLst->glow, 'rad', 'integer') / Properties::POINTS_WIDTH_MULTIPLIER;
|
$axisGlowSize = (float) self::getAttribute($sppr->effectLst->glow, 'rad', 'integer') / ChartProperties::POINTS_WIDTH_MULTIPLIER;
|
||||||
if ($axisGlowSize != 0.0) {
|
if ($axisGlowSize != 0.0) {
|
||||||
$colorArray = $this->readColor($sppr->effectLst->glow);
|
$colorArray = $this->readColor($sppr->effectLst->glow);
|
||||||
$chartObject->setGlowProperties($axisGlowSize, $colorArray['value'], $colorArray['alpha'], $colorArray['type']);
|
$chartObject->setGlowProperties($axisGlowSize, $colorArray['value'], $colorArray['alpha'], $colorArray['type']);
|
||||||
|
|
@ -1180,7 +1182,7 @@ class Chart
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$softEdgeSize = self::getAttribute($sppr->effectLst->softEdge, 'rad', 'string');
|
$softEdgeSize = self::getAttribute($sppr->effectLst->softEdge, 'rad', 'string');
|
||||||
if (is_numeric($softEdgeSize)) {
|
if (is_numeric($softEdgeSize)) {
|
||||||
$chartObject->setSoftEdges((float) Properties::xmlToPoints($softEdgeSize));
|
$chartObject->setSoftEdges((float) ChartProperties::xmlToPoints($softEdgeSize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1195,20 +1197,20 @@ class Chart
|
||||||
if ($type !== '') {
|
if ($type !== '') {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$blur = self::getAttribute($sppr->effectLst->$type, 'blurRad', 'string');
|
$blur = self::getAttribute($sppr->effectLst->$type, 'blurRad', 'string');
|
||||||
$blur = is_numeric($blur) ? Properties::xmlToPoints($blur) : null;
|
$blur = is_numeric($blur) ? ChartProperties::xmlToPoints($blur) : null;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$dist = self::getAttribute($sppr->effectLst->$type, 'dist', 'string');
|
$dist = self::getAttribute($sppr->effectLst->$type, 'dist', 'string');
|
||||||
$dist = is_numeric($dist) ? Properties::xmlToPoints($dist) : null;
|
$dist = is_numeric($dist) ? ChartProperties::xmlToPoints($dist) : null;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$direction = self::getAttribute($sppr->effectLst->$type, 'dir', 'string');
|
$direction = self::getAttribute($sppr->effectLst->$type, 'dir', 'string');
|
||||||
$direction = is_numeric($direction) ? Properties::xmlToAngle($direction) : null;
|
$direction = is_numeric($direction) ? ChartProperties::xmlToAngle($direction) : null;
|
||||||
$algn = self::getAttribute($sppr->effectLst->$type, 'algn', 'string');
|
$algn = self::getAttribute($sppr->effectLst->$type, 'algn', 'string');
|
||||||
$rot = self::getAttribute($sppr->effectLst->$type, 'rotWithShape', 'string');
|
$rot = self::getAttribute($sppr->effectLst->$type, 'rotWithShape', 'string');
|
||||||
$size = [];
|
$size = [];
|
||||||
foreach (['sx', 'sy'] as $sizeType) {
|
foreach (['sx', 'sy'] as $sizeType) {
|
||||||
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
|
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
|
||||||
if (is_numeric($sizeValue)) {
|
if (is_numeric($sizeValue)) {
|
||||||
$size[$sizeType] = Properties::xmlToTenthOfPercent((string) $sizeValue);
|
$size[$sizeType] = ChartProperties::xmlToTenthOfPercent((string) $sizeValue);
|
||||||
} else {
|
} else {
|
||||||
$size[$sizeType] = null;
|
$size[$sizeType] = null;
|
||||||
}
|
}
|
||||||
|
|
@ -1216,7 +1218,7 @@ class Chart
|
||||||
foreach (['kx', 'ky'] as $sizeType) {
|
foreach (['kx', 'ky'] as $sizeType) {
|
||||||
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
|
$sizeValue = self::getAttribute($sppr->effectLst->$type, $sizeType, 'string');
|
||||||
if (is_numeric($sizeValue)) {
|
if (is_numeric($sizeValue)) {
|
||||||
$size[$sizeType] = Properties::xmlToAngle((string) $sizeValue);
|
$size[$sizeType] = ChartProperties::xmlToAngle((string) $sizeValue);
|
||||||
} else {
|
} else {
|
||||||
$size[$sizeType] = null;
|
$size[$sizeType] = null;
|
||||||
}
|
}
|
||||||
|
|
@ -1273,7 +1275,7 @@ class Chart
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function readLineStyle(SimpleXMLElement $chartDetail, ?Properties $chartObject): void
|
private function readLineStyle(SimpleXMLElement $chartDetail, ?ChartProperties $chartObject): void
|
||||||
{
|
{
|
||||||
if (!isset($chartObject, $chartDetail->spPr)) {
|
if (!isset($chartObject, $chartDetail->spPr)) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1287,7 +1289,7 @@ class Chart
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$lineWidthTemp = self::getAttribute($sppr->ln, 'w', 'string');
|
$lineWidthTemp = self::getAttribute($sppr->ln, 'w', 'string');
|
||||||
if (is_numeric($lineWidthTemp)) {
|
if (is_numeric($lineWidthTemp)) {
|
||||||
$lineWidth = Properties::xmlToPoints($lineWidthTemp);
|
$lineWidth = ChartProperties::xmlToPoints($lineWidthTemp);
|
||||||
}
|
}
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$compoundType = self::getAttribute($sppr->ln, 'cmpd', 'string');
|
$compoundType = self::getAttribute($sppr->ln, 'cmpd', 'string');
|
||||||
|
|
@ -1296,15 +1298,13 @@ class Chart
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$capType = self::getAttribute($sppr->ln, 'cap', 'string');
|
$capType = self::getAttribute($sppr->ln, 'cap', 'string');
|
||||||
if (isset($sppr->ln->miter)) {
|
if (isset($sppr->ln->miter)) {
|
||||||
$joinType = Properties::LINE_STYLE_JOIN_MITER;
|
$joinType = ChartProperties::LINE_STYLE_JOIN_MITER;
|
||||||
} elseif (isset($sppr->ln->bevel)) {
|
} elseif (isset($sppr->ln->bevel)) {
|
||||||
$joinType = Properties::LINE_STYLE_JOIN_BEVEL;
|
$joinType = ChartProperties::LINE_STYLE_JOIN_BEVEL;
|
||||||
} else {
|
} else {
|
||||||
$joinType = '';
|
$joinType = '';
|
||||||
}
|
}
|
||||||
$headArrowType = '';
|
|
||||||
$headArrowSize = '';
|
$headArrowSize = '';
|
||||||
$endArrowType = '';
|
|
||||||
$endArrowSize = '';
|
$endArrowSize = '';
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$headArrowType = self::getAttribute($sppr->ln->headEnd, 'type', 'string');
|
$headArrowType = self::getAttribute($sppr->ln->headEnd, 'type', 'string');
|
||||||
|
|
@ -1403,7 +1403,7 @@ class Chart
|
||||||
/** @var string */
|
/** @var string */
|
||||||
$textRotation = self::getAttribute($children->bodyPr, 'rot', 'string');
|
$textRotation = self::getAttribute($children->bodyPr, 'rot', 'string');
|
||||||
if (is_numeric($textRotation)) {
|
if (is_numeric($textRotation)) {
|
||||||
$whichAxis->setAxisOption('textRotation', (string) Properties::xmlToAngle($textRotation));
|
$whichAxis->setAxisOption('textRotation', (string) ChartProperties::xmlToAngle($textRotation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -724,6 +724,19 @@ class Spreadsheet
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get sheet by name, throwing exception if not found.
|
||||||
|
*/
|
||||||
|
public function getSheetByNameOrThrow(string $worksheetName): Worksheet
|
||||||
|
{
|
||||||
|
$worksheet = $this->getSheetByName($worksheetName);
|
||||||
|
if ($worksheet === null) {
|
||||||
|
throw new Exception("Sheet $worksheetName does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $worksheet;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get index for sheet.
|
* Get index for sheet.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,27 @@ class Alignment extends Supervisor
|
||||||
const HORIZONTAL_JUSTIFY = 'justify';
|
const HORIZONTAL_JUSTIFY = 'justify';
|
||||||
const HORIZONTAL_FILL = 'fill';
|
const HORIZONTAL_FILL = 'fill';
|
||||||
const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
|
const HORIZONTAL_DISTRIBUTED = 'distributed'; // Excel2007 only
|
||||||
|
private const HORIZONTAL_CENTER_CONTINUOUS_LC = 'centercontinuous';
|
||||||
|
// Mapping for horizontal alignment
|
||||||
|
const HORIZONTAL_ALIGNMENT_FOR_XLSX = [
|
||||||
|
self::HORIZONTAL_LEFT => self::HORIZONTAL_LEFT,
|
||||||
|
self::HORIZONTAL_RIGHT => self::HORIZONTAL_RIGHT,
|
||||||
|
self::HORIZONTAL_CENTER => self::HORIZONTAL_CENTER,
|
||||||
|
self::HORIZONTAL_CENTER_CONTINUOUS => self::HORIZONTAL_CENTER_CONTINUOUS,
|
||||||
|
self::HORIZONTAL_JUSTIFY => self::HORIZONTAL_JUSTIFY,
|
||||||
|
self::HORIZONTAL_FILL => self::HORIZONTAL_FILL,
|
||||||
|
self::HORIZONTAL_DISTRIBUTED => self::HORIZONTAL_DISTRIBUTED,
|
||||||
|
];
|
||||||
|
// Mapping for horizontal alignment CSS
|
||||||
|
const HORIZONTAL_ALIGNMENT_FOR_HTML = [
|
||||||
|
self::HORIZONTAL_LEFT => self::HORIZONTAL_LEFT,
|
||||||
|
self::HORIZONTAL_RIGHT => self::HORIZONTAL_RIGHT,
|
||||||
|
self::HORIZONTAL_CENTER => self::HORIZONTAL_CENTER,
|
||||||
|
self::HORIZONTAL_CENTER_CONTINUOUS => self::HORIZONTAL_CENTER,
|
||||||
|
self::HORIZONTAL_JUSTIFY => self::HORIZONTAL_JUSTIFY,
|
||||||
|
//self::HORIZONTAL_FILL => self::HORIZONTAL_FILL, // no reasonable equivalent for fill
|
||||||
|
self::HORIZONTAL_DISTRIBUTED => self::HORIZONTAL_JUSTIFY,
|
||||||
|
];
|
||||||
|
|
||||||
// Vertical alignment styles
|
// Vertical alignment styles
|
||||||
const VERTICAL_BOTTOM = 'bottom';
|
const VERTICAL_BOTTOM = 'bottom';
|
||||||
|
|
@ -22,6 +43,45 @@ class Alignment extends Supervisor
|
||||||
const VERTICAL_CENTER = 'center';
|
const VERTICAL_CENTER = 'center';
|
||||||
const VERTICAL_JUSTIFY = 'justify';
|
const VERTICAL_JUSTIFY = 'justify';
|
||||||
const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only
|
const VERTICAL_DISTRIBUTED = 'distributed'; // Excel2007 only
|
||||||
|
// Vertical alignment CSS
|
||||||
|
private const VERTICAL_BASELINE = 'baseline';
|
||||||
|
private const VERTICAL_MIDDLE = 'middle';
|
||||||
|
private const VERTICAL_SUB = 'sub';
|
||||||
|
private const VERTICAL_SUPER = 'super';
|
||||||
|
private const VERTICAL_TEXT_BOTTOM = 'text-bottom';
|
||||||
|
private const VERTICAL_TEXT_TOP = 'text-top';
|
||||||
|
|
||||||
|
// Mapping for vertical alignment
|
||||||
|
const VERTICAL_ALIGNMENT_FOR_XLSX = [
|
||||||
|
self::VERTICAL_BOTTOM => self::VERTICAL_BOTTOM,
|
||||||
|
self::VERTICAL_TOP => self::VERTICAL_TOP,
|
||||||
|
self::VERTICAL_CENTER => self::VERTICAL_CENTER,
|
||||||
|
self::VERTICAL_JUSTIFY => self::VERTICAL_JUSTIFY,
|
||||||
|
self::VERTICAL_DISTRIBUTED => self::VERTICAL_DISTRIBUTED,
|
||||||
|
// css settings that arent't in sync with Excel
|
||||||
|
self::VERTICAL_BASELINE => self::VERTICAL_BOTTOM,
|
||||||
|
self::VERTICAL_MIDDLE => self::VERTICAL_CENTER,
|
||||||
|
self::VERTICAL_SUB => self::VERTICAL_BOTTOM,
|
||||||
|
self::VERTICAL_SUPER => self::VERTICAL_TOP,
|
||||||
|
self::VERTICAL_TEXT_BOTTOM => self::VERTICAL_BOTTOM,
|
||||||
|
self::VERTICAL_TEXT_TOP => self::VERTICAL_TOP,
|
||||||
|
];
|
||||||
|
|
||||||
|
// Mapping for vertical alignment for Html
|
||||||
|
const VERTICAL_ALIGNMENT_FOR_HTML = [
|
||||||
|
self::VERTICAL_BOTTOM => self::VERTICAL_BOTTOM,
|
||||||
|
self::VERTICAL_TOP => self::VERTICAL_TOP,
|
||||||
|
self::VERTICAL_CENTER => self::VERTICAL_MIDDLE,
|
||||||
|
self::VERTICAL_JUSTIFY => self::VERTICAL_MIDDLE,
|
||||||
|
self::VERTICAL_DISTRIBUTED => self::VERTICAL_MIDDLE,
|
||||||
|
// css settings that arent't in sync with Excel
|
||||||
|
self::VERTICAL_BASELINE => self::VERTICAL_BASELINE,
|
||||||
|
self::VERTICAL_MIDDLE => self::VERTICAL_MIDDLE,
|
||||||
|
self::VERTICAL_SUB => self::VERTICAL_SUB,
|
||||||
|
self::VERTICAL_SUPER => self::VERTICAL_SUPER,
|
||||||
|
self::VERTICAL_TEXT_BOTTOM => self::VERTICAL_TEXT_BOTTOM,
|
||||||
|
self::VERTICAL_TEXT_TOP => self::VERTICAL_TEXT_TOP,
|
||||||
|
];
|
||||||
|
|
||||||
// Read order
|
// Read order
|
||||||
const READORDER_CONTEXT = 0;
|
const READORDER_CONTEXT = 0;
|
||||||
|
|
@ -202,8 +262,9 @@ class Alignment extends Supervisor
|
||||||
*/
|
*/
|
||||||
public function setHorizontal(string $horizontalAlignment)
|
public function setHorizontal(string $horizontalAlignment)
|
||||||
{
|
{
|
||||||
if ($horizontalAlignment == '') {
|
$horizontalAlignment = strtolower($horizontalAlignment);
|
||||||
$horizontalAlignment = self::HORIZONTAL_GENERAL;
|
if ($horizontalAlignment === self::HORIZONTAL_CENTER_CONTINUOUS_LC) {
|
||||||
|
$horizontalAlignment = self::HORIZONTAL_CENTER_CONTINUOUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isSupervisor) {
|
if ($this->isSupervisor) {
|
||||||
|
|
@ -239,9 +300,7 @@ class Alignment extends Supervisor
|
||||||
*/
|
*/
|
||||||
public function setVertical($verticalAlignment)
|
public function setVertical($verticalAlignment)
|
||||||
{
|
{
|
||||||
if ($verticalAlignment == '') {
|
$verticalAlignment = strtolower($verticalAlignment);
|
||||||
$verticalAlignment = self::VERTICAL_BOTTOM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->isSupervisor) {
|
if ($this->isSupervisor) {
|
||||||
$styleArray = $this->getStyleArray(['vertical' => $verticalAlignment]);
|
$styleArray = $this->getStyleArray(['vertical' => $verticalAlignment]);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ class PercentageFormatter extends BaseFormatter
|
||||||
|
|
||||||
$format = str_replace('%', '%%', $format);
|
$format = str_replace('%', '%%', $format);
|
||||||
$wholePartSize = strlen((string) floor($value));
|
$wholePartSize = strlen((string) floor($value));
|
||||||
$decimalPartSize = $placeHolders = 0;
|
$decimalPartSize = 0;
|
||||||
|
$placeHolders = '';
|
||||||
// Number of decimals
|
// Number of decimals
|
||||||
if (preg_match('/\.([?0]+)/u', $format, $matches)) {
|
if (preg_match('/\.([?0]+)/u', $format, $matches)) {
|
||||||
$decimalPartSize = strlen($matches[1]);
|
$decimalPartSize = strlen($matches[1]);
|
||||||
|
|
@ -29,12 +30,13 @@ class PercentageFormatter extends BaseFormatter
|
||||||
$placeHolders = str_repeat(' ', strlen($matches[1]) - $decimalPartSize);
|
$placeHolders = str_repeat(' ', strlen($matches[1]) - $decimalPartSize);
|
||||||
}
|
}
|
||||||
// Number of digits to display before the decimal
|
// Number of digits to display before the decimal
|
||||||
if (preg_match('/([#0,]+)\./u', $format, $matches)) {
|
if (preg_match('/([#0,]+)\.?/u', $format, $matches)) {
|
||||||
$wholePartSize = max($wholePartSize, strlen($matches[1]));
|
$firstZero = preg_replace('/^[#,]*/', '', $matches[1]);
|
||||||
|
$wholePartSize = max($wholePartSize, strlen($firstZero));
|
||||||
}
|
}
|
||||||
|
|
||||||
$wholePartSize += $decimalPartSize;
|
$wholePartSize += $decimalPartSize + (int) ($decimalPartSize > 0);
|
||||||
$replacement = "{$wholePartSize}.{$decimalPartSize}";
|
$replacement = "0{$wholePartSize}.{$decimalPartSize}";
|
||||||
$mask = (string) preg_replace('/[#0,]+\.?[?#0,]*/ui', "%{$replacement}f{$placeHolders}", $format);
|
$mask = (string) preg_replace('/[#0,]+\.?[?#0,]*/ui', "%{$replacement}f{$placeHolders}", $format);
|
||||||
|
|
||||||
/** @var float */
|
/** @var float */
|
||||||
|
|
|
||||||
|
|
@ -259,10 +259,11 @@ class PageSetup
|
||||||
/**
|
/**
|
||||||
* First page number.
|
* First page number.
|
||||||
*
|
*
|
||||||
* @var int
|
* @var ?int
|
||||||
*/
|
*/
|
||||||
private $firstPageNumber;
|
private $firstPageNumber;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
private $pageOrder = self::PAGEORDER_DOWN_THEN_OVER;
|
private $pageOrder = self::PAGEORDER_DOWN_THEN_OVER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -375,7 +376,7 @@ class PageSetup
|
||||||
{
|
{
|
||||||
// Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
|
// Microsoft Office Excel 2007 only allows setting a scale between 10 and 400 via the user interface,
|
||||||
// but it is apparently still able to handle any scale >= 0, where 0 results in 100
|
// but it is apparently still able to handle any scale >= 0, where 0 results in 100
|
||||||
if (($scale >= 0) || $scale === null) {
|
if ($scale === null || $scale >= 0) {
|
||||||
$this->scale = $scale;
|
$this->scale = $scale;
|
||||||
if ($update) {
|
if ($update) {
|
||||||
$this->fitToPage = false;
|
$this->fitToPage = false;
|
||||||
|
|
@ -845,7 +846,7 @@ class PageSetup
|
||||||
/**
|
/**
|
||||||
* Get first page number.
|
* Get first page number.
|
||||||
*
|
*
|
||||||
* @return int
|
* @return ?int
|
||||||
*/
|
*/
|
||||||
public function getFirstPageNumber()
|
public function getFirstPageNumber()
|
||||||
{
|
{
|
||||||
|
|
@ -855,7 +856,7 @@ class PageSetup
|
||||||
/**
|
/**
|
||||||
* Set first page number.
|
* Set first page number.
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param ?int $value
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1359,7 +1359,7 @@ class Worksheet implements IComparable
|
||||||
|
|
||||||
if ($rowDimension !== null && $rowDimension->getXfIndex() > 0) {
|
if ($rowDimension !== null && $rowDimension->getXfIndex() > 0) {
|
||||||
// then there is a row dimension with explicit style, assign it to the cell
|
// then there is a row dimension with explicit style, assign it to the cell
|
||||||
$cell->setXfIndex($rowDimension->getXfIndex());
|
$cell->setXfIndex(/** @scrutinizer ignore-type */ $rowDimension->getXfIndex());
|
||||||
} elseif ($columnDimension !== null && $columnDimension->getXfIndex() > 0) {
|
} elseif ($columnDimension !== null && $columnDimension->getXfIndex() > 0) {
|
||||||
// then there is a column dimension, assign it to the cell
|
// then there is a column dimension, assign it to the cell
|
||||||
$cell->setXfIndex($columnDimension->getXfIndex());
|
$cell->setXfIndex($columnDimension->getXfIndex());
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Style;
|
use PhpOffice\PhpSpreadsheet\Style\Style;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
|
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
class Html extends BaseWriter
|
class Html extends BaseWriter
|
||||||
|
|
@ -230,13 +231,6 @@ class Html extends BaseWriter
|
||||||
$this->editHtmlCallback = $callback;
|
$this->editHtmlCallback = $callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VALIGN_ARR = [
|
|
||||||
Alignment::VERTICAL_BOTTOM => 'bottom',
|
|
||||||
Alignment::VERTICAL_TOP => 'top',
|
|
||||||
Alignment::VERTICAL_CENTER => 'middle',
|
|
||||||
Alignment::VERTICAL_JUSTIFY => 'middle',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map VAlign.
|
* Map VAlign.
|
||||||
*
|
*
|
||||||
|
|
@ -246,17 +240,9 @@ class Html extends BaseWriter
|
||||||
*/
|
*/
|
||||||
private function mapVAlign($vAlign)
|
private function mapVAlign($vAlign)
|
||||||
{
|
{
|
||||||
return array_key_exists($vAlign, self::VALIGN_ARR) ? self::VALIGN_ARR[$vAlign] : 'baseline';
|
return Alignment::VERTICAL_ALIGNMENT_FOR_HTML[$vAlign] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const HALIGN_ARR = [
|
|
||||||
Alignment::HORIZONTAL_LEFT => 'left',
|
|
||||||
Alignment::HORIZONTAL_RIGHT => 'right',
|
|
||||||
Alignment::HORIZONTAL_CENTER => 'center',
|
|
||||||
Alignment::HORIZONTAL_CENTER_CONTINUOUS => 'center',
|
|
||||||
Alignment::HORIZONTAL_JUSTIFY => 'justify',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map HAlign.
|
* Map HAlign.
|
||||||
*
|
*
|
||||||
|
|
@ -266,7 +252,7 @@ class Html extends BaseWriter
|
||||||
*/
|
*/
|
||||||
private function mapHAlign($hAlign)
|
private function mapHAlign($hAlign)
|
||||||
{
|
{
|
||||||
return array_key_exists($hAlign, self::HALIGN_ARR) ? self::HALIGN_ARR[$hAlign] : '';
|
return Alignment::HORIZONTAL_ALIGNMENT_FOR_HTML[$hAlign] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const BORDER_ARR = [
|
const BORDER_ARR = [
|
||||||
|
|
@ -988,7 +974,10 @@ class Html extends BaseWriter
|
||||||
$css = [];
|
$css = [];
|
||||||
|
|
||||||
// Create CSS
|
// Create CSS
|
||||||
$css['vertical-align'] = $this->mapVAlign($alignment->getVertical() ?? '');
|
$verticalAlign = $this->mapVAlign($alignment->getVertical() ?? '');
|
||||||
|
if ($verticalAlign) {
|
||||||
|
$css['vertical-align'] = $verticalAlign;
|
||||||
|
}
|
||||||
$textAlign = $this->mapHAlign($alignment->getHorizontal() ?? '');
|
$textAlign = $this->mapHAlign($alignment->getHorizontal() ?? '');
|
||||||
if ($textAlign) {
|
if ($textAlign) {
|
||||||
$css['text-align'] = $textAlign;
|
$css['text-align'] = $textAlign;
|
||||||
|
|
@ -1289,23 +1278,22 @@ class Html extends BaseWriter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateRowCellDataValue(Worksheet $worksheet, Cell $cell, ?string &$cellData): void
|
private function generateRowCellDataValue(Worksheet $worksheet, Cell $cell, string &$cellData): void
|
||||||
{
|
{
|
||||||
if ($cell->getValue() instanceof RichText) {
|
if ($cell->getValue() instanceof RichText) {
|
||||||
$this->generateRowCellDataValueRich($cell, $cellData);
|
$this->generateRowCellDataValueRich($cell, $cellData);
|
||||||
} else {
|
} else {
|
||||||
$origData = $this->preCalculateFormulas ? $cell->getCalculatedValue() : $cell->getValue();
|
$origData = $this->preCalculateFormulas ? $cell->getCalculatedValue() : $cell->getValue();
|
||||||
$formatCode = $worksheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode();
|
$formatCode = $worksheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode();
|
||||||
if ($formatCode !== null) {
|
|
||||||
$cellData = NumberFormat::toFormattedString(
|
$cellData = NumberFormat::toFormattedString(
|
||||||
$origData,
|
$origData ?? '',
|
||||||
$formatCode,
|
$formatCode ?? NumberFormat::FORMAT_GENERAL,
|
||||||
[$this, 'formatColor']
|
[$this, 'formatColor']
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if ($cellData === $origData) {
|
if ($cellData === $origData) {
|
||||||
$cellData = htmlspecialchars($cellData ?? '', Settings::htmlEntityFlags());
|
$cellData = htmlspecialchars($cellData, Settings::htmlEntityFlags());
|
||||||
}
|
}
|
||||||
if ($worksheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperscript()) {
|
if ($worksheet->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont()->getSuperscript()) {
|
||||||
$cellData = '<sup>' . $cellData . '</sup>';
|
$cellData = '<sup>' . $cellData . '</sup>';
|
||||||
|
|
@ -1489,8 +1477,8 @@ class Html extends BaseWriter
|
||||||
&& $this->isSpannedCell[$worksheet->getParent()->getIndex($worksheet)][$row + 1][$colNum]);
|
&& $this->isSpannedCell[$worksheet->getParent()->getIndex($worksheet)][$row + 1][$colNum]);
|
||||||
|
|
||||||
// Colspan and Rowspan
|
// Colspan and Rowspan
|
||||||
$colspan = 1;
|
$colSpan = 1;
|
||||||
$rowspan = 1;
|
$rowSpan = 1;
|
||||||
if (isset($this->isBaseCell[$worksheet->getParent()->getIndex($worksheet)][$row + 1][$colNum])) {
|
if (isset($this->isBaseCell[$worksheet->getParent()->getIndex($worksheet)][$row + 1][$colNum])) {
|
||||||
$spans = $this->isBaseCell[$worksheet->getParent()->getIndex($worksheet)][$row + 1][$colNum];
|
$spans = $this->isBaseCell[$worksheet->getParent()->getIndex($worksheet)][$row + 1][$colNum];
|
||||||
$rowSpan = $spans['rowspan'];
|
$rowSpan = $spans['rowspan'];
|
||||||
|
|
@ -1803,7 +1791,8 @@ class Html extends BaseWriter
|
||||||
|
|
||||||
public function getOrientation(): ?string
|
public function getOrientation(): ?string
|
||||||
{
|
{
|
||||||
return null;
|
// Expect Pdf classes to override this method.
|
||||||
|
return $this->isPdf ? PageSetup::ORIENTATION_PORTRAIT : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1842,9 +1831,9 @@ class Html extends BaseWriter
|
||||||
$bottom = StringHelper::FormatNumber($worksheet->getPageMargins()->getBottom()) . 'in; ';
|
$bottom = StringHelper::FormatNumber($worksheet->getPageMargins()->getBottom()) . 'in; ';
|
||||||
$htmlPage .= 'margin-bottom: ' . $bottom;
|
$htmlPage .= 'margin-bottom: ' . $bottom;
|
||||||
$orientation = $this->getOrientation() ?? $worksheet->getPageSetup()->getOrientation();
|
$orientation = $this->getOrientation() ?? $worksheet->getPageSetup()->getOrientation();
|
||||||
if ($orientation === \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE) {
|
if ($orientation === PageSetup::ORIENTATION_LANDSCAPE) {
|
||||||
$htmlPage .= 'size: landscape; ';
|
$htmlPage .= 'size: landscape; ';
|
||||||
} elseif ($orientation === \PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_PORTRAIT) {
|
} elseif ($orientation === PageSetup::ORIENTATION_PORTRAIT) {
|
||||||
$htmlPage .= 'size: portrait; ';
|
$htmlPage .= 'size: portrait; ';
|
||||||
}
|
}
|
||||||
$htmlPage .= '}' . PHP_EOL;
|
$htmlPage .= '}' . PHP_EOL;
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,7 @@ class Worksheet extends BIFFwriter
|
||||||
switch ($calctype) {
|
switch ($calctype) {
|
||||||
case 'integer':
|
case 'integer':
|
||||||
case 'double':
|
case 'double':
|
||||||
$this->writeNumber($row, $column, $calculatedValue, $xfIndex);
|
$this->writeNumber($row, $column, (float) $calculatedValue, $xfIndex);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
|
|
@ -473,7 +473,7 @@ class Worksheet extends BIFFwriter
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$this->writeBoolErr($row, $column, $calculatedValue, 0, $xfIndex);
|
$this->writeBoolErr($row, $column, (int) $calculatedValue, 0, $xfIndex);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
|
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Borders;
|
use PhpOffice\PhpSpreadsheet\Style\Borders;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
use PhpOffice\PhpSpreadsheet\Style\Conditional;
|
||||||
|
|
@ -403,8 +404,14 @@ class Style extends WriterPart
|
||||||
|
|
||||||
// alignment
|
// alignment
|
||||||
$objWriter->startElement('alignment');
|
$objWriter->startElement('alignment');
|
||||||
$objWriter->writeAttribute('horizontal', (string) $style->getAlignment()->getHorizontal());
|
$vertical = Alignment::VERTICAL_ALIGNMENT_FOR_XLSX[$style->getAlignment()->getVertical()] ?? '';
|
||||||
$objWriter->writeAttribute('vertical', (string) $style->getAlignment()->getVertical());
|
$horizontal = Alignment::HORIZONTAL_ALIGNMENT_FOR_XLSX[$style->getAlignment()->getHorizontal()] ?? '';
|
||||||
|
if ($horizontal !== '') {
|
||||||
|
$objWriter->writeAttribute('horizontal', $horizontal);
|
||||||
|
}
|
||||||
|
if ($vertical !== '') {
|
||||||
|
$objWriter->writeAttribute('vertical', $vertical);
|
||||||
|
}
|
||||||
|
|
||||||
$textRotation = 0;
|
$textRotation = 0;
|
||||||
if ($style->getAlignment()->getTextRotation() >= 0) {
|
if ($style->getAlignment()->getTextRotation() >= 0) {
|
||||||
|
|
@ -459,11 +466,13 @@ class Style extends WriterPart
|
||||||
|
|
||||||
// alignment
|
// alignment
|
||||||
$objWriter->startElement('alignment');
|
$objWriter->startElement('alignment');
|
||||||
if ($style->getAlignment()->getHorizontal() !== null) {
|
$horizontal = Alignment::HORIZONTAL_ALIGNMENT_FOR_XLSX[$style->getAlignment()->getHorizontal()] ?? '';
|
||||||
$objWriter->writeAttribute('horizontal', $style->getAlignment()->getHorizontal());
|
if ($horizontal) {
|
||||||
|
$objWriter->writeAttribute('horizontal', $horizontal);
|
||||||
}
|
}
|
||||||
if ($style->getAlignment()->getVertical() !== null) {
|
$vertical = Alignment::VERTICAL_ALIGNMENT_FOR_XLSX[$style->getAlignment()->getVertical()] ?? '';
|
||||||
$objWriter->writeAttribute('vertical', $style->getAlignment()->getVertical());
|
if ($vertical) {
|
||||||
|
$objWriter->writeAttribute('vertical', $vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($style->getAlignment()->getTextRotation() !== null) {
|
if ($style->getAlignment()->getTextRotation() !== null) {
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,7 @@ class Worksheet extends WriterPart
|
||||||
private static function writeTimePeriodCondElements(XMLWriter $objWriter, Conditional $conditional, string $cellCoordinate): void
|
private static function writeTimePeriodCondElements(XMLWriter $objWriter, Conditional $conditional, string $cellCoordinate): void
|
||||||
{
|
{
|
||||||
$txt = $conditional->getText();
|
$txt = $conditional->getText();
|
||||||
if ($txt !== null) {
|
if (!empty($txt)) {
|
||||||
$objWriter->writeAttribute('timePeriod', $txt);
|
$objWriter->writeAttribute('timePeriod', $txt);
|
||||||
if (empty($conditional->getConditions())) {
|
if (empty($conditional->getConditions())) {
|
||||||
if ($conditional->getOperatorType() == Conditional::TIMEPERIOD_TODAY) {
|
if ($conditional->getOperatorType() == Conditional::TIMEPERIOD_TODAY) {
|
||||||
|
|
@ -536,7 +536,7 @@ class Worksheet extends WriterPart
|
||||||
private static function writeTextCondElements(XMLWriter $objWriter, Conditional $conditional, string $cellCoordinate): void
|
private static function writeTextCondElements(XMLWriter $objWriter, Conditional $conditional, string $cellCoordinate): void
|
||||||
{
|
{
|
||||||
$txt = $conditional->getText();
|
$txt = $conditional->getText();
|
||||||
if ($txt !== null) {
|
if (!empty($txt)) {
|
||||||
$objWriter->writeAttribute('text', $txt);
|
$objWriter->writeAttribute('text', $txt);
|
||||||
if (empty($conditional->getConditions())) {
|
if (empty($conditional->getConditions())) {
|
||||||
if ($conditional->getOperatorType() == Conditional::OPERATOR_CONTAINSTEXT) {
|
if ($conditional->getOperatorType() == Conditional::OPERATOR_CONTAINSTEXT) {
|
||||||
|
|
@ -1034,7 +1034,7 @@ class Worksheet extends WriterPart
|
||||||
} else {
|
} else {
|
||||||
$objWriter->writeAttribute('fitToWidth', '0');
|
$objWriter->writeAttribute('fitToWidth', '0');
|
||||||
}
|
}
|
||||||
if ($worksheet->getPageSetup()->getFirstPageNumber() !== null) {
|
if (!empty($worksheet->getPageSetup()->getFirstPageNumber())) {
|
||||||
$objWriter->writeAttribute('firstPageNumber', (string) $worksheet->getPageSetup()->getFirstPageNumber());
|
$objWriter->writeAttribute('firstPageNumber', (string) $worksheet->getPageSetup()->getFirstPageNumber());
|
||||||
$objWriter->writeAttribute('useFirstPageNumber', '1');
|
$objWriter->writeAttribute('useFirstPageNumber', '1');
|
||||||
}
|
}
|
||||||
|
|
@ -1228,7 +1228,7 @@ class Worksheet extends WriterPart
|
||||||
StringHelper::controlCharacterPHP2OOXML(htmlspecialchars($cellValue, Settings::htmlEntityFlags()))
|
StringHelper::controlCharacterPHP2OOXML(htmlspecialchars($cellValue, Settings::htmlEntityFlags()))
|
||||||
);
|
);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
} elseif ($cellValue instanceof RichText) {
|
} else {
|
||||||
$objWriter->startElement('is');
|
$objWriter->startElement('is');
|
||||||
$this->getParentWriter()->getWriterPartstringtable()->writeRichText($objWriter, $cellValue);
|
$this->getParentWriter()->getWriterPartstringtable()->writeRichText($objWriter, $cellValue);
|
||||||
$objWriter->endElement();
|
$objWriter->endElement();
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ConvertUoMTest extends TestCase
|
class ConvertUoMTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
const UOM_PRECISION = 1E-12;
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetConversionGroups(): void
|
public function testGetConversionGroups(): void
|
||||||
{
|
{
|
||||||
|
|
@ -52,7 +48,7 @@ class ConvertUoMTest extends TestCase
|
||||||
public function testCONVERTUOM($expectedResult, ...$args): void
|
public function testCONVERTUOM($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = Engineering::CONVERTUOM(...$args);
|
$result = Engineering::CONVERTUOM(...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEqualsWithDelta($expectedResult, $result, self::UOM_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerCONVERTUOM(): array
|
public function providerCONVERTUOM(): array
|
||||||
|
|
@ -69,7 +65,7 @@ class ConvertUoMTest extends TestCase
|
||||||
|
|
||||||
$formula = "=CONVERT({$value}, {$fromUoM}, {$toUoM})";
|
$formula = "=CONVERT({$value}, {$fromUoM}, {$toUoM})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
self::assertEqualsWithDelta($expectedResult, $result, self::UOM_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerConvertUoMArray(): array
|
public function providerConvertUoMArray(): array
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ErfCTest extends TestCase
|
class ErfCTest extends TestCase
|
||||||
{
|
{
|
||||||
const ERF_PRECISION = 1E-12;
|
const ERF_PRECISION = 1E-12;
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerERFC
|
* @dataProvider providerERFC
|
||||||
*
|
*
|
||||||
|
|
@ -25,7 +19,6 @@ class ErfCTest extends TestCase
|
||||||
public function testERFC($expectedResult, $lower): void
|
public function testERFC($expectedResult, $lower): void
|
||||||
{
|
{
|
||||||
$result = Engineering::ERFC($lower);
|
$result = Engineering::ERFC($lower);
|
||||||
self::assertEquals($expectedResult, $result);
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +36,7 @@ class ErfCTest extends TestCase
|
||||||
|
|
||||||
$formula = "=ERFC({$lower})";
|
$formula = "=ERFC({$lower})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerErfCArray(): array
|
public function providerErfCArray(): array
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ErfPreciseTest extends TestCase
|
class ErfPreciseTest extends TestCase
|
||||||
{
|
{
|
||||||
const ERF_PRECISION = 1E-12;
|
const ERF_PRECISION = 1E-12;
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerERFPRECISE
|
* @dataProvider providerERFPRECISE
|
||||||
*
|
*
|
||||||
|
|
@ -25,7 +19,6 @@ class ErfPreciseTest extends TestCase
|
||||||
public function testERFPRECISE($expectedResult, $limit): void
|
public function testERFPRECISE($expectedResult, $limit): void
|
||||||
{
|
{
|
||||||
$result = Engineering::ERFPRECISE($limit);
|
$result = Engineering::ERFPRECISE($limit);
|
||||||
self::assertEquals($expectedResult, $result);
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +36,7 @@ class ErfPreciseTest extends TestCase
|
||||||
|
|
||||||
$formula = "=ERF.PRECISE({$limit})";
|
$formula = "=ERF.PRECISE({$limit})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerErfPreciseArray(): array
|
public function providerErfPreciseArray(): array
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,12 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ErfTest extends TestCase
|
class ErfTest extends TestCase
|
||||||
{
|
{
|
||||||
const ERF_PRECISION = 1E-12;
|
const ERF_PRECISION = 1E-12;
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerERF
|
* @dataProvider providerERF
|
||||||
*
|
*
|
||||||
|
|
@ -26,7 +20,6 @@ class ErfTest extends TestCase
|
||||||
public function testERF($expectedResult, $lower, $upper = null): void
|
public function testERF($expectedResult, $lower, $upper = null): void
|
||||||
{
|
{
|
||||||
$result = Engineering::ERF($lower, $upper);
|
$result = Engineering::ERF($lower, $upper);
|
||||||
self::assertEquals($expectedResult, $result);
|
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,7 +37,7 @@ class ErfTest extends TestCase
|
||||||
|
|
||||||
$formula = "=ERF({$lower}, {$upper})";
|
$formula = "=ERF({$lower}, {$upper})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
self::assertEqualsWithDelta($expectedResult, $result, self::ERF_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerErfArray(): array
|
public function providerErfArray(): array
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,15 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Engineering;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
use PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ParseComplexTest extends TestCase
|
class ParseComplexTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testParseComplex(): void
|
public function testParseComplex(): void
|
||||||
{
|
{
|
||||||
[$real, $imaginary, $suffix] = [1.23e-4, 5.67e+8, 'j'];
|
[$real, $imaginary, $suffix] = [1.23e-4, 5.67e+8, 'j'];
|
||||||
|
|
||||||
$result = Engineering::parseComplex('1.23e-4+5.67e+8j');
|
$result = /** @scrutinizer ignore-deprecated */ Engineering::parseComplex('1.23e-4+5.67e+8j');
|
||||||
self::assertArrayHasKey('real', $result);
|
self::assertArrayHasKey('real', $result);
|
||||||
self::assertEquals($real, $result['real']);
|
self::assertEquals($real, $result['real']);
|
||||||
self::assertArrayHasKey('imaginary', $result);
|
self::assertArrayHasKey('imaginary', $result);
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,45 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
|
class IrrTest extends AllSetupTeardown
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class IrrTest extends TestCase
|
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerIRR
|
* @dataProvider providerIRR
|
||||||
*
|
*
|
||||||
* @param mixed $expectedResult
|
* @param mixed $expectedResult
|
||||||
|
* @param mixed $values
|
||||||
*/
|
*/
|
||||||
public function testIRR($expectedResult, ...$args): void
|
public function testIRR($expectedResult, $values = null): void
|
||||||
{
|
{
|
||||||
$result = Financial::IRR(...$args);
|
$this->mightHaveException($expectedResult);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
$sheet = $this->getSheet();
|
||||||
|
$formula = '=IRR(';
|
||||||
|
if ($values !== null) {
|
||||||
|
if (is_array($values)) {
|
||||||
|
$row = 0;
|
||||||
|
foreach ($values as $value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
foreach ($value as $arrayValue) {
|
||||||
|
++$row;
|
||||||
|
$sheet->getCell("A$row")->setValue($arrayValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
++$row;
|
||||||
|
$sheet->getCell("A$row")->setValue($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$formula .= "A1:A$row";
|
||||||
|
} else {
|
||||||
|
$sheet->getCell('A1')->setValue($values);
|
||||||
|
$formula .= 'A1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$formula .= ')';
|
||||||
|
$sheet->getCell('D1')->setValue($formula);
|
||||||
|
$result = $sheet->getCell('D1')->getCalculatedValue();
|
||||||
|
$this->adjustResult($result, $expectedResult);
|
||||||
|
|
||||||
|
self::assertEqualsWithDelta($expectedResult, $result, 0.1E-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerIRR(): array
|
public function providerIRR(): array
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ColumnsTest extends TestCase
|
class ColumnsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerCOLUMNS
|
* @dataProvider providerCOLUMNS
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +15,7 @@ class ColumnsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testCOLUMNS($expectedResult, ...$args): void
|
public function testCOLUMNS($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = LookupRef::COLUMNS(...$args);
|
$result = LookupRef::COLUMNS(/** @scrutinizer ignore-type */ ...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class IndexTest extends TestCase
|
class IndexTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerINDEX
|
* @dataProvider providerINDEX
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +15,7 @@ class IndexTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testINDEX($expectedResult, ...$args): void
|
public function testINDEX($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = LookupRef::INDEX(...$args);
|
$result = LookupRef::INDEX(/** @scrutinizer ignore-type */ ...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,11 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class RowsTest extends TestCase
|
class RowsTest extends TestCase
|
||||||
{
|
{
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerROWS
|
* @dataProvider providerROWS
|
||||||
*
|
*
|
||||||
|
|
@ -21,7 +15,7 @@ class RowsTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testROWS($expectedResult, ...$args): void
|
public function testROWS($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = LookupRef::ROWS(...$args);
|
$result = LookupRef::ROWS(/** @scrutinizer ignore-type */ ...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
|
|
||||||
class FactTest extends AllSetupTeardown
|
class FactTest extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
|
const FACT_PRECISION = 1E-12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerFACT
|
* @dataProvider providerFACT
|
||||||
*
|
*
|
||||||
|
|
@ -53,7 +55,7 @@ class FactTest extends AllSetupTeardown
|
||||||
$sheet->getCell('B1')->setValue('=FACT(A1)');
|
$sheet->getCell('B1')->setValue('=FACT(A1)');
|
||||||
}
|
}
|
||||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEqualsWithDelta($expectedResult, $result, self::FACT_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerFACTGnumeric(): array
|
public function providerFACTGnumeric(): array
|
||||||
|
|
@ -70,7 +72,7 @@ class FactTest extends AllSetupTeardown
|
||||||
|
|
||||||
$formula = "=FACT({$array})";
|
$formula = "=FACT({$array})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
self::assertEqualsWithDelta($expectedResult, $result, self::FACT_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerFactArray(): array
|
public function providerFactArray(): array
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\MatrixFunctions;
|
||||||
|
|
||||||
class MUnitTest extends AllSetupTeardown
|
class MUnitTest extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
|
const MU_PRECISION = 1.0E-12;
|
||||||
|
|
||||||
public function testMUNIT(): void
|
public function testMUNIT(): void
|
||||||
{
|
{
|
||||||
$identity = MatrixFunctions::identity(3);
|
$identity = MatrixFunctions::identity(3);
|
||||||
|
|
@ -15,7 +17,7 @@ class MUnitTest extends AllSetupTeardown
|
||||||
self::assertEquals($startArray, $resultArray);
|
self::assertEquals($startArray, $resultArray);
|
||||||
$inverseArray = MatrixFunctions::inverse($startArray);
|
$inverseArray = MatrixFunctions::inverse($startArray);
|
||||||
$resultArray = MatrixFunctions::multiply($startArray, $inverseArray);
|
$resultArray = MatrixFunctions::multiply($startArray, $inverseArray);
|
||||||
self::assertEquals($identity, $resultArray);
|
self::assertEqualsWithDelta($identity, $resultArray, self::MU_PRECISION);
|
||||||
self::assertEquals('#VALUE!', MatrixFunctions::identity(0));
|
self::assertEquals('#VALUE!', MatrixFunctions::identity(0));
|
||||||
self::assertEquals('#VALUE!', MatrixFunctions::identity(-1));
|
self::assertEquals('#VALUE!', MatrixFunctions::identity(-1));
|
||||||
self::assertEquals('#VALUE!', MatrixFunctions::identity('X'));
|
self::assertEquals('#VALUE!', MatrixFunctions::identity('X'));
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class RandBetweenTest extends AllSetupTeardown
|
||||||
$formula = "=RandBetween({$argument1}, {$argument2})";
|
$formula = "=RandBetween({$argument1}, {$argument2})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertIsArray($result);
|
self::assertIsArray($result);
|
||||||
self::assertCount($expectedRows, $result);
|
self::assertCount($expectedRows, /** @scrutinizer ignore-type */ $result);
|
||||||
self::assertIsArray($result[0]);
|
self::assertIsArray($result[0]);
|
||||||
self::assertCount($expectedColumns, /** @scrutinizer ignore-type */ $result[0]);
|
self::assertCount($expectedColumns, /** @scrutinizer ignore-type */ $result[0]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||||
|
|
||||||
class NumberValueTest extends AllSetupTeardown
|
class NumberValueTest extends AllSetupTeardown
|
||||||
{
|
{
|
||||||
|
const NV_PRECISION = 1.0E-8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerNUMBERVALUE
|
* @dataProvider providerNUMBERVALUE
|
||||||
*
|
*
|
||||||
|
|
@ -34,7 +36,7 @@ class NumberValueTest extends AllSetupTeardown
|
||||||
$sheet->getCell('B1')->setValue('=NUMBERVALUE(A1, A2, A3)');
|
$sheet->getCell('B1')->setValue('=NUMBERVALUE(A1, A2, A3)');
|
||||||
}
|
}
|
||||||
$result = $sheet->getCell('B1')->getCalculatedValue();
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEqualsWithDelta($expectedResult, $result, self::NV_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerNUMBERVALUE(): array
|
public function providerNUMBERVALUE(): array
|
||||||
|
|
@ -51,7 +53,7 @@ class NumberValueTest extends AllSetupTeardown
|
||||||
|
|
||||||
$formula = "=NumberValue({$argument1}, {$argument2}, {$argument3})";
|
$formula = "=NumberValue({$argument1}, {$argument2}, {$argument3})";
|
||||||
$result = $calculation->_calculateFormulaValue($formula);
|
$result = $calculation->_calculateFormulaValue($formula);
|
||||||
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
self::assertEqualsWithDelta($expectedResult, $result, self::NV_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerNumberValueArray(): array
|
public function providerNumberValueArray(): array
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class AdvancedValueBinderTest extends TestCase
|
class AdvancedValueBinderTest extends TestCase
|
||||||
{
|
{
|
||||||
|
const AVB_PRECISION = 1.0E-8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
|
|
@ -161,7 +163,7 @@ class AdvancedValueBinderTest extends TestCase
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
$sheet->getCell('A1')->setValue($value);
|
$sheet->getCell('A1')->setValue($value);
|
||||||
self::assertEquals($valueBinded, $sheet->getCell('A1')->getValue());
|
self::assertEqualsWithDelta($valueBinded, $sheet->getCell('A1')->getValue(), self::AVB_PRECISION);
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ class DefinedNameTest extends TestCase
|
||||||
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addDefinedName(
|
$this->spreadsheet->addDefinedName(
|
||||||
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertCount(2, $this->spreadsheet->getDefinedNames());
|
self::assertCount(2, $this->spreadsheet->getDefinedNames());
|
||||||
|
|
@ -66,7 +66,7 @@ class DefinedNameTest extends TestCase
|
||||||
self::assertNotNull($definedName1);
|
self::assertNotNull($definedName1);
|
||||||
self::assertSame('=A1', $definedName1->getValue());
|
self::assertSame('=A1', $definedName1->getValue());
|
||||||
|
|
||||||
$definedName2 = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$definedName2 = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($definedName2);
|
self::assertNotNull($definedName2);
|
||||||
self::assertSame('=B1', $definedName2->getValue());
|
self::assertSame('=B1', $definedName2->getValue());
|
||||||
}
|
}
|
||||||
|
|
@ -103,13 +103,13 @@ class DefinedNameTest extends TestCase
|
||||||
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addDefinedName(
|
$this->spreadsheet->addDefinedName(
|
||||||
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getActiveSheet());
|
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
||||||
$definedName = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$definedName = $this->spreadsheet->getDefinedName('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($definedName);
|
self::assertNotNull($definedName);
|
||||||
self::assertSame('=B1', $definedName->getValue());
|
self::assertSame('=B1', $definedName->getValue());
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +120,10 @@ class DefinedNameTest extends TestCase
|
||||||
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
DefinedName::createInstance('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addDefinedName(
|
$this->spreadsheet->addDefinedName(
|
||||||
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
DefinedName::createInstance('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$this->spreadsheet->removeDefinedName('Foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
self::assertCount(1, $this->spreadsheet->getDefinedNames());
|
||||||
$definedName = $this->spreadsheet->getDefinedName('foo');
|
$definedName = $this->spreadsheet->getDefinedName('foo');
|
||||||
|
|
@ -154,10 +154,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testChangeWorksheet(): void
|
public function testChangeWorksheet(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
@ -172,10 +170,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testLocalOnly(): void
|
public function testLocalOnly(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
@ -190,10 +186,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testScope(): void
|
public function testScope(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
@ -208,10 +202,8 @@ class DefinedNameTest extends TestCase
|
||||||
|
|
||||||
public function testClone(): void
|
public function testClone(): void
|
||||||
{
|
{
|
||||||
$sheet1 = $this->spreadsheet->getSheetByName('Sheet #1');
|
$sheet1 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #1');
|
||||||
$sheet2 = $this->spreadsheet->getSheetByName('Sheet #2');
|
$sheet2 = $this->spreadsheet->getSheetByNameOrThrow('Sheet #2');
|
||||||
self::assertNotNull($sheet1);
|
|
||||||
self::assertNotNull($sheet2);
|
|
||||||
|
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->setValue(2);
|
$sheet2->getCell('A1')->setValue(2);
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,7 @@ class PrintAreaTest extends AbstractFunctional
|
||||||
|
|
||||||
private static function getPrintArea(Spreadsheet $spreadsheet, string $name): string
|
private static function getPrintArea(Spreadsheet $spreadsheet, string $name): string
|
||||||
{
|
{
|
||||||
$sheet = $spreadsheet->getSheetByName($name);
|
$sheet = $spreadsheet->getSheetByNameOrThrow($name);
|
||||||
self::assertNotNull($sheet, "Unable to get sheet $name");
|
|
||||||
|
|
||||||
return $sheet->getPageSetup()->getPrintArea();
|
return $sheet->getPageSetup()->getPrintArea();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,6 @@ class SampleTest extends TestCase
|
||||||
{
|
{
|
||||||
$skipped = [
|
$skipped = [
|
||||||
];
|
];
|
||||||
if (PHP_VERSION_ID >= 80200) {
|
|
||||||
// Hopefully temporary. Continue to try
|
|
||||||
// 32_chart_read_write_PDF/HTML
|
|
||||||
// so as not to lose track of the problem.
|
|
||||||
$skipped[] = 'Chart/35_Chart_render.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unfortunately some tests are too long to run with code-coverage
|
// Unfortunately some tests are too long to run with code-coverage
|
||||||
// analysis on GitHub Actions, so we need to exclude them
|
// analysis on GitHub Actions, so we need to exclude them
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class NamedFormulaTest extends TestCase
|
||||||
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedFormula(
|
$this->spreadsheet->addNamedFormula(
|
||||||
new NamedFormula('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=16%', true)
|
new NamedFormula('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=16%', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertCount(2, $this->spreadsheet->getNamedFormulae());
|
self::assertCount(2, $this->spreadsheet->getNamedFormulae());
|
||||||
|
|
@ -72,7 +72,7 @@ class NamedFormulaTest extends TestCase
|
||||||
'=19%',
|
'=19%',
|
||||||
$formula->getValue()
|
$formula->getValue()
|
||||||
);
|
);
|
||||||
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($formula);
|
self::assertNotNull($formula);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=16%',
|
'=16%',
|
||||||
|
|
@ -100,13 +100,13 @@ class NamedFormulaTest extends TestCase
|
||||||
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedFormula(
|
$this->spreadsheet->addNamedFormula(
|
||||||
new NamedFormula('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=16%', true)
|
new NamedFormula('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=16%', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getActiveSheet());
|
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
||||||
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$formula = $this->spreadsheet->getNamedFormula('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($formula);
|
self::assertNotNull($formula);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=16%',
|
'=16%',
|
||||||
|
|
@ -120,10 +120,10 @@ class NamedFormulaTest extends TestCase
|
||||||
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
new NamedFormula('Foo', $this->spreadsheet->getActiveSheet(), '=19%')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedFormula(
|
$this->spreadsheet->addNamedFormula(
|
||||||
new NamedFormula('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=16%', true)
|
new NamedFormula('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=16%', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$this->spreadsheet->removeNamedFormula('Foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
self::assertCount(1, $this->spreadsheet->getNamedFormulae());
|
||||||
$formula = $this->spreadsheet->getNamedFormula('foo');
|
$formula = $this->spreadsheet->getNamedFormula('foo');
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class NamedRangeTest extends TestCase
|
||||||
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedRange(
|
$this->spreadsheet->addNamedRange(
|
||||||
new NamedRange('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
new NamedRange('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
self::assertCount(2, $this->spreadsheet->getNamedRanges());
|
self::assertCount(2, $this->spreadsheet->getNamedRanges());
|
||||||
|
|
@ -72,7 +72,7 @@ class NamedRangeTest extends TestCase
|
||||||
'=A1',
|
'=A1',
|
||||||
$range->getValue()
|
$range->getValue()
|
||||||
);
|
);
|
||||||
$range = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$range = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($range);
|
self::assertNotNull($range);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=B1',
|
'=B1',
|
||||||
|
|
@ -100,13 +100,13 @@ class NamedRangeTest extends TestCase
|
||||||
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedRange(
|
$this->spreadsheet->addNamedRange(
|
||||||
new NamedRange('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
new NamedRange('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getActiveSheet());
|
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getActiveSheet());
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
||||||
$sheet = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$sheet = $this->spreadsheet->getNamedRange('foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
self::assertNotNull($sheet);
|
self::assertNotNull($sheet);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
'=B1',
|
'=B1',
|
||||||
|
|
@ -120,10 +120,10 @@ class NamedRangeTest extends TestCase
|
||||||
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
new NamedRange('Foo', $this->spreadsheet->getActiveSheet(), '=A1')
|
||||||
);
|
);
|
||||||
$this->spreadsheet->addNamedRange(
|
$this->spreadsheet->addNamedRange(
|
||||||
new NamedRange('FOO', $this->spreadsheet->getSheetByName('Sheet #2'), '=B1', true)
|
new NamedRange('FOO', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'), '=B1', true)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getSheetByName('Sheet #2'));
|
$this->spreadsheet->removeNamedRange('Foo', $this->spreadsheet->getSheetByNameOrThrow('Sheet #2'));
|
||||||
|
|
||||||
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
self::assertCount(1, $this->spreadsheet->getNamedRanges());
|
||||||
$range = $this->spreadsheet->getNamedRange('foo');
|
$range = $this->spreadsheet->getNamedRange('foo');
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,11 @@ class CsvContiguousTest extends TestCase
|
||||||
|
|
||||||
private static function getCellValue(Spreadsheet $spreadsheet, string $sheetName, string $cellAddress): string
|
private static function getCellValue(Spreadsheet $spreadsheet, string $sheetName, string $cellAddress): string
|
||||||
{
|
{
|
||||||
$sheet = $spreadsheet->getSheetByName($sheetName);
|
$sheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
$result = '';
|
$result = '';
|
||||||
if ($sheet !== null) {
|
$value = $sheet->getCell($cellAddress)->getValue();
|
||||||
$value = $sheet->getCell($cellAddress)->getValue();
|
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
|
||||||
if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) {
|
$result = (string) $value;
|
||||||
$result = (string) $value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,16 @@ class NumberFormatGeneralTest extends AbstractFunctional
|
||||||
|
|
||||||
$reader = new Xls();
|
$reader = new Xls();
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$sheet = $spreadsheet->getSheetByName('Blad1');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Blad1');
|
||||||
if ($sheet === null) {
|
$array = $sheet->toArray();
|
||||||
self::fail('Expected to find sheet Blad1');
|
self::assertSame('€ 2.95', $array[1][3]);
|
||||||
} else {
|
self::assertSame(2.95, $sheet->getCell('D2')->getValue());
|
||||||
$array = $sheet->toArray();
|
self::assertSame(2.95, $sheet->getCell('D2')->getCalculatedValue());
|
||||||
self::assertSame('€ 2.95', $array[1][3]);
|
self::assertSame('€ 2.95', $sheet->getCell('D2')->getFormattedValue());
|
||||||
self::assertSame(2.95, $sheet->getCell('D2')->getValue());
|
self::assertSame(21, $array[1][4]);
|
||||||
self::assertSame(2.95, $sheet->getCell('D2')->getCalculatedValue());
|
self::assertSame(21, $sheet->getCell('E2')->getValue());
|
||||||
self::assertSame('€ 2.95', $sheet->getCell('D2')->getFormattedValue());
|
self::assertSame(21, $sheet->getCell('E2')->getCalculatedValue());
|
||||||
self::assertSame(21, $array[1][4]);
|
self::assertSame('21', $sheet->getCell('E2')->getFormattedValue());
|
||||||
self::assertSame(21, $sheet->getCell('E2')->getValue());
|
|
||||||
self::assertSame(21, $sheet->getCell('E2')->getCalculatedValue());
|
|
||||||
self::assertSame('21', $sheet->getCell('E2')->getFormattedValue());
|
|
||||||
}
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,7 @@ class RichTextSizeTest extends AbstractFunctional
|
||||||
$filename = 'tests/data/Reader/XLS/RichTextFontSize.xls';
|
$filename = 'tests/data/Reader/XLS/RichTextFontSize.xls';
|
||||||
$reader = new Xls();
|
$reader = new Xls();
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$sheet = $spreadsheet->getSheetByName('橱柜门板');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('橱柜门板');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$text = $sheet->getCell('L15')->getValue();
|
$text = $sheet->getCell('L15')->getValue();
|
||||||
$elements = $text->getRichTextElements();
|
$elements = $text->getRichTextElements();
|
||||||
self::assertEquals(10, $elements[2]->getFont()->getSize());
|
self::assertEquals(10, $elements[2]->getFont()->getSize());
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ class AutoFilter2Test extends TestCase
|
||||||
public function testReadDateRange(): void
|
public function testReadDateRange(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('daterange');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('daterange');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$filter = $sheet->getAutoFilter();
|
$filter = $sheet->getAutoFilter();
|
||||||
$maxRow = 30;
|
$maxRow = 30;
|
||||||
self::assertSame("A1:A$maxRow", $filter->getRange());
|
self::assertSame("A1:A$maxRow", $filter->getRange());
|
||||||
|
|
@ -61,8 +60,7 @@ class AutoFilter2Test extends TestCase
|
||||||
public function testReadTopTen(): void
|
public function testReadTopTen(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('top10');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('top10');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$filter = $sheet->getAutoFilter();
|
$filter = $sheet->getAutoFilter();
|
||||||
$maxRow = 65;
|
$maxRow = 65;
|
||||||
self::assertSame("A1:A$maxRow", $filter->getRange());
|
self::assertSame("A1:A$maxRow", $filter->getRange());
|
||||||
|
|
@ -70,6 +68,7 @@ class AutoFilter2Test extends TestCase
|
||||||
self::assertCount(1, $columns);
|
self::assertCount(1, $columns);
|
||||||
$column = $columns['A'] ?? null;
|
$column = $columns['A'] ?? null;
|
||||||
self::assertNotNull($column);
|
self::assertNotNull($column);
|
||||||
|
/** @scrutinizer ignore-call */
|
||||||
$ruleset = $column->getRules();
|
$ruleset = $column->getRules();
|
||||||
self::assertCount(1, $ruleset);
|
self::assertCount(1, $ruleset);
|
||||||
$rule = $ruleset[0];
|
$rule = $ruleset[0];
|
||||||
|
|
@ -86,8 +85,7 @@ class AutoFilter2Test extends TestCase
|
||||||
public function testReadDynamic(): void
|
public function testReadDynamic(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('dynamic');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('dynamic');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$filter = $sheet->getAutoFilter();
|
$filter = $sheet->getAutoFilter();
|
||||||
$maxRow = 30;
|
$maxRow = 30;
|
||||||
self::assertSame("A1:A$maxRow", $filter->getRange());
|
self::assertSame("A1:A$maxRow", $filter->getRange());
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class ChartSheetTest extends TestCase
|
class ChartSheetTest extends TestCase
|
||||||
|
|
@ -16,8 +15,7 @@ class ChartSheetTest extends TestCase
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
|
|
||||||
self::assertCount(2, $spreadsheet->getAllSheets());
|
self::assertCount(2, $spreadsheet->getAllSheets());
|
||||||
$chartSheet = $spreadsheet->getSheetByName('Chart1');
|
$chartSheet = $spreadsheet->getSheetByNameOrThrow('Chart1');
|
||||||
self::assertInstanceOf(Worksheet::class, $chartSheet);
|
|
||||||
self::assertSame(1, $chartSheet->getChartCount());
|
self::assertSame(1, $chartSheet->getChartCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +27,6 @@ class ChartSheetTest extends TestCase
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
|
|
||||||
self::assertCount(1, $spreadsheet->getAllSheets());
|
self::assertCount(1, $spreadsheet->getAllSheets());
|
||||||
$chartSheet = $spreadsheet->getSheetByName('Chart1');
|
self::assertNull($spreadsheet->getSheetByName('Chart1'));
|
||||||
self::assertNull($chartSheet);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,28 +42,20 @@ class Issue2501Test extends TestCase
|
||||||
$filename = self::$testbook;
|
$filename = self::$testbook;
|
||||||
$reader = IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$sheet = $spreadsheet->getSheetByName('Columns');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Columns');
|
||||||
$expected = [
|
$expected = [
|
||||||
'A1:A1048576',
|
'A1:A1048576',
|
||||||
'B1:D1048576',
|
'B1:D1048576',
|
||||||
'E2:E4',
|
'E2:E4',
|
||||||
];
|
];
|
||||||
if ($sheet === null) {
|
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
||||||
self::fail('Unable to find sheet Columns');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('Rows');
|
||||||
} else {
|
|
||||||
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
|
||||||
}
|
|
||||||
$sheet = $spreadsheet->getSheetByName('Rows');
|
|
||||||
$expected = [
|
$expected = [
|
||||||
'A1:XFD1',
|
'A1:XFD1',
|
||||||
'A2:XFD4',
|
'A2:XFD4',
|
||||||
'B5:D5',
|
'B5:D5',
|
||||||
];
|
];
|
||||||
if ($sheet === null) {
|
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
||||||
self::fail('Unable to find sheet Rows');
|
|
||||||
} else {
|
|
||||||
self::assertSame($expected, array_values($sheet->getMergeCells()));
|
|
||||||
}
|
|
||||||
|
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,9 @@ class NamespaceNonStdTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertSame('A2', $sheet->getFreezePane());
|
self::assertSame('A2', $sheet->getFreezePane());
|
||||||
self::assertSame('A2', $sheet->getTopLeftCell());
|
self::assertSame('A2', $sheet->getTopLeftCell());
|
||||||
self::assertSame('B3', $sheet->getSelectedCells());
|
self::assertSame('B3', $sheet->getSelectedCells());
|
||||||
$sheet = $spreadsheet->getSheetByName('SylkTest');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('SylkTest');
|
||||||
if ($sheet === null) {
|
self::assertNull($sheet->getFreezePane());
|
||||||
self::fail('Unable to load expected sheet');
|
self::assertNull($sheet->getTopLeftCell());
|
||||||
} else {
|
|
||||||
self::assertNull($sheet->getFreezePane());
|
|
||||||
self::assertNull($sheet->getTopLeftCell());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadXlsx(): void
|
public function testLoadXlsx(): void
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,9 @@ class NamespaceOpenpyxl35Test extends \PHPUnit\Framework\TestCase
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
foreach ($expectedArray as $sheetName => $array1) {
|
foreach ($expectedArray as $sheetName => $array1) {
|
||||||
$sheet = $spreadsheet->getSheetByName($sheetName);
|
$sheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
if ($sheet === null) {
|
foreach ($array1 as $key => $value) {
|
||||||
self::fail("Unable to find sheet $sheetName");
|
self::assertSame($value, self::getCellValue($sheet, $key), "error in sheet $sheetName cell $key");
|
||||||
} else {
|
|
||||||
foreach ($array1 as $key => $value) {
|
|
||||||
self::assertSame($value, self::getCellValue($sheet, $key), "error in sheet $sheetName cell $key");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$spreadsheet->disconnectWorksheets();
|
$spreadsheet->disconnectWorksheets();
|
||||||
|
|
|
||||||
|
|
@ -62,13 +62,9 @@ class NamespaceStdTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertSame('A2', $sheet->getFreezePane());
|
self::assertSame('A2', $sheet->getFreezePane());
|
||||||
self::assertSame('A2', $sheet->getTopLeftCell());
|
self::assertSame('A2', $sheet->getTopLeftCell());
|
||||||
self::assertSame('B3', $sheet->getSelectedCells());
|
self::assertSame('B3', $sheet->getSelectedCells());
|
||||||
$sheet = $spreadsheet->getSheetByName('SylkTest');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('SylkTest');
|
||||||
if ($sheet === null) {
|
self::assertNull($sheet->getFreezePane());
|
||||||
self::fail('Unable to load expected sheet');
|
self::assertNull($sheet->getTopLeftCell());
|
||||||
} else {
|
|
||||||
self::assertNull($sheet->getFreezePane());
|
|
||||||
self::assertNull($sheet->getTopLeftCell());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadXlsx(): void
|
public function testLoadXlsx(): void
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,7 @@ class PageSetup2Test extends TestCase
|
||||||
public function testColumnBreak(): void
|
public function testColumnBreak(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
$spreadsheet = IOFactory::load(self::TESTBOOK);
|
||||||
$sheet = $spreadsheet->getSheetByName('colbreak');
|
$sheet = $spreadsheet->getSheetByNameOrThrow('colbreak');
|
||||||
self::assertNotNull($sheet);
|
|
||||||
$breaks = $sheet->getBreaks();
|
$breaks = $sheet->getBreaks();
|
||||||
self::assertCount(1, $breaks);
|
self::assertCount(1, $breaks);
|
||||||
$break = $breaks['D1'] ?? null;
|
$break = $breaks['D1'] ?? null;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class XlsxTest extends TestCase
|
class XlsxTest extends TestCase
|
||||||
{
|
{
|
||||||
|
const XLSX_PRECISION = 1.0E-8;
|
||||||
|
|
||||||
public function testLoadXlsxRowColumnAttributes(): void
|
public function testLoadXlsxRowColumnAttributes(): void
|
||||||
{
|
{
|
||||||
$filename = 'tests/data/Reader/XLSX/rowColumnAttributeTest.xlsx';
|
$filename = 'tests/data/Reader/XLSX/rowColumnAttributeTest.xlsx';
|
||||||
|
|
@ -133,10 +135,10 @@ class XlsxTest extends TestCase
|
||||||
|
|
||||||
$pageMargins = $worksheet->getPageMargins();
|
$pageMargins = $worksheet->getPageMargins();
|
||||||
// Convert from inches to cm for testing
|
// Convert from inches to cm for testing
|
||||||
self::assertEquals(2.5, $pageMargins->getTop() * 2.54);
|
self::assertEqualsWithDelta(2.5, $pageMargins->getTop() * 2.54, self::XLSX_PRECISION);
|
||||||
self::assertEquals(3.3, $pageMargins->getLeft() * 2.54);
|
self::assertEqualsWithDelta(3.3, $pageMargins->getLeft() * 2.54, self::XLSX_PRECISION);
|
||||||
self::assertEquals(3.3, $pageMargins->getRight() * 2.54);
|
self::assertEqualsWithDelta(3.3, $pageMargins->getRight() * 2.54, self::XLSX_PRECISION);
|
||||||
self::assertEquals(1.3, $pageMargins->getHeader() * 2.54);
|
self::assertEqualsWithDelta(1.3, $pageMargins->getHeader() * 2.54, self::XLSX_PRECISION);
|
||||||
|
|
||||||
self::assertEquals(PageSetup::PAPERSIZE_A4, $worksheet->getPageSetup()->getPaperSize());
|
self::assertEquals(PageSetup::PAPERSIZE_A4, $worksheet->getPageSetup()->getPaperSize());
|
||||||
self::assertEquals(['A10', 'A20', 'A30', 'A40', 'A50'], array_keys($worksheet->getBreaks()));
|
self::assertEquals(['A10', 'A20', 'A30', 'A40', 'A50'], array_keys($worksheet->getBreaks()));
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,6 @@ class RichTextTest extends TestCase
|
||||||
public function testTextElements(): void
|
public function testTextElements(): void
|
||||||
{
|
{
|
||||||
$element1 = new TextElement('A');
|
$element1 = new TextElement('A');
|
||||||
if ($element1->getFont() !== null) {
|
|
||||||
self::fail('Expected font to be null');
|
|
||||||
}
|
|
||||||
$element2 = new TextElement('B');
|
$element2 = new TextElement('B');
|
||||||
$element3 = new TextElement('C');
|
$element3 = new TextElement('C');
|
||||||
$richText = new RichText();
|
$richText = new RichText();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class FontTest extends TestCase
|
class FontTest extends TestCase
|
||||||
{
|
{
|
||||||
|
const FONT_PRECISION = 1.0E-12;
|
||||||
|
|
||||||
public function testGetAutoSizeMethod(): void
|
public function testGetAutoSizeMethod(): void
|
||||||
{
|
{
|
||||||
$expectedResult = Font::AUTOSIZE_METHOD_APPROX;
|
$expectedResult = Font::AUTOSIZE_METHOD_APPROX;
|
||||||
|
|
@ -63,7 +65,7 @@ class FontTest extends TestCase
|
||||||
public function testInchSizeToPixels($expectedResult, $size): void
|
public function testInchSizeToPixels($expectedResult, $size): void
|
||||||
{
|
{
|
||||||
$result = Font::inchSizeToPixels($size);
|
$result = Font::inchSizeToPixels($size);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEqualsWithDelta($expectedResult, $result, self::FONT_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerInchSizeToPixels(): array
|
public function providerInchSizeToPixels(): array
|
||||||
|
|
@ -80,7 +82,7 @@ class FontTest extends TestCase
|
||||||
public function testCentimeterSizeToPixels($expectedResult, $size): void
|
public function testCentimeterSizeToPixels($expectedResult, $size): void
|
||||||
{
|
{
|
||||||
$result = Font::centimeterSizeToPixels($size);
|
$result = Font::centimeterSizeToPixels($size);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEqualsWithDelta($expectedResult, $result, self::FONT_PRECISION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerCentimeterSizeToPixels(): array
|
public function providerCentimeterSizeToPixels(): array
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,27 @@ class PasswordHasherTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerHashPassword
|
* @dataProvider providerHashPassword
|
||||||
*
|
|
||||||
* @param mixed $expectedResult
|
|
||||||
*/
|
*/
|
||||||
public function testHashPassword($expectedResult, ...$args): void
|
public function testHashPassword(
|
||||||
{
|
string $expectedResult,
|
||||||
|
string $password,
|
||||||
|
?string $algorithm = null,
|
||||||
|
?string $salt = null,
|
||||||
|
?int $spinCount = null
|
||||||
|
): void {
|
||||||
if ($expectedResult === 'exception') {
|
if ($expectedResult === 'exception') {
|
||||||
$this->expectException(SpException::class);
|
$this->expectException(SpException::class);
|
||||||
}
|
}
|
||||||
$result = PasswordHasher::hashPassword(...$args);
|
if ($algorithm === null) {
|
||||||
self::assertEquals($expectedResult, $result);
|
$result = PasswordHasher::hashPassword($password);
|
||||||
|
} elseif ($salt === null) {
|
||||||
|
$result = PasswordHasher::hashPassword($password, $algorithm);
|
||||||
|
} elseif ($spinCount === null) {
|
||||||
|
$result = PasswordHasher::hashPassword($password, $algorithm, $salt);
|
||||||
|
} else {
|
||||||
|
$result = PasswordHasher::hashPassword($password, $algorithm, $salt, $spinCount);
|
||||||
|
}
|
||||||
|
self::assertSame($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerHashPassword(): array
|
public function providerHashPassword(): array
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class LinearBestFitTest extends TestCase
|
class LinearBestFitTest extends TestCase
|
||||||
{
|
{
|
||||||
|
const LBF_PRECISION = 1.0E-8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider providerLinearBestFit
|
* @dataProvider providerLinearBestFit
|
||||||
*
|
*
|
||||||
|
|
@ -27,13 +29,13 @@ class LinearBestFitTest extends TestCase
|
||||||
): void {
|
): void {
|
||||||
$bestFit = new LinearBestFit($yValues, $xValues);
|
$bestFit = new LinearBestFit($yValues, $xValues);
|
||||||
$slope = $bestFit->getSlope(1);
|
$slope = $bestFit->getSlope(1);
|
||||||
self::assertEquals($expectedSlope[0], $slope);
|
self::assertEqualsWithDelta($expectedSlope[0], $slope, self::LBF_PRECISION);
|
||||||
$slope = $bestFit->getSlope();
|
$slope = $bestFit->getSlope();
|
||||||
self::assertEquals($expectedSlope[1], $slope);
|
self::assertEqualsWithDelta($expectedSlope[1], $slope, self::LBF_PRECISION);
|
||||||
$intersect = $bestFit->getIntersect(1);
|
$intersect = $bestFit->getIntersect(1);
|
||||||
self::assertEquals($expectedIntersect[0], $intersect);
|
self::assertEqualsWithDelta($expectedIntersect[0], $intersect, self::LBF_PRECISION);
|
||||||
$intersect = $bestFit->getIntersect();
|
$intersect = $bestFit->getIntersect();
|
||||||
self::assertEquals($expectedIntersect[1], $intersect);
|
self::assertEqualsWithDelta($expectedIntersect[1], $intersect, self::LBF_PRECISION);
|
||||||
|
|
||||||
$equation = $bestFit->getEquation(2);
|
$equation = $bestFit->getEquation(2);
|
||||||
self::assertEquals($expectedEquation, $equation);
|
self::assertEquals($expectedEquation, $equation);
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,38 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests;
|
namespace PhpOffice\PhpSpreadsheetTests;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Exception as ssException;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class SpreadsheetTest extends TestCase
|
class SpreadsheetTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var Spreadsheet */
|
/** @var ?Spreadsheet */
|
||||||
private $object;
|
private $spreadsheet;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
if ($this->spreadsheet !== null) {
|
||||||
$this->object = new Spreadsheet();
|
$this->spreadsheet->disconnectWorksheets();
|
||||||
$sheet = $this->object->getActiveSheet();
|
$this->spreadsheet = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getSpreadsheet(): Spreadsheet
|
||||||
|
{
|
||||||
|
$this->spreadsheet = $spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
|
||||||
$sheet->setTitle('someSheet1');
|
$sheet->setTitle('someSheet1');
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet2');
|
$sheet->setTitle('someSheet2');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet 3');
|
$sheet->setTitle('someSheet 3');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
|
|
||||||
|
return $spreadsheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderForSheetNames(): array
|
public function dataProviderForSheetNames(): array
|
||||||
|
|
@ -35,6 +45,7 @@ class SpreadsheetTest extends TestCase
|
||||||
[1, "'someSheet2'"],
|
[1, "'someSheet2'"],
|
||||||
[2, 'someSheet 3'],
|
[2, 'someSheet 3'],
|
||||||
[2, "'someSheet 3'"],
|
[2, "'someSheet 3'"],
|
||||||
|
[null, 'someSheet 33'],
|
||||||
];
|
];
|
||||||
|
|
||||||
return $array;
|
return $array;
|
||||||
|
|
@ -43,135 +54,153 @@ class SpreadsheetTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataProviderForSheetNames
|
* @dataProvider dataProviderForSheetNames
|
||||||
*/
|
*/
|
||||||
public function testGetSheetByName(int $index, string $sheetName): void
|
public function testGetSheetByName(?int $index, string $sheetName): void
|
||||||
{
|
{
|
||||||
self::assertSame($this->object->getSheet($index), $this->object->getSheetByName($sheetName));
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
|
if ($index === null) {
|
||||||
|
self::assertNull($spreadsheet->getSheetByName($sheetName));
|
||||||
|
} else {
|
||||||
|
self::assertSame($spreadsheet->getSheet($index), $spreadsheet->getSheetByName($sheetName));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSheetDuplicateTitle(): void
|
public function testAddSheetDuplicateTitle(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
|
$this->expectException(ssException::class);
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet2');
|
$sheet->setTitle('someSheet2');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSheetNoAdjustActive(): void
|
public function testAddSheetNoAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet4');
|
$sheet->setTitle('someSheet4');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddSheetAdjustActive(): void
|
public function testAddSheetAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet0');
|
$sheet->setTitle('someSheet0');
|
||||||
$this->object->addSheet($sheet, 0);
|
$spreadsheet->addSheet($sheet, 0);
|
||||||
self::assertEquals(3, $this->object->getActiveSheetIndex());
|
self::assertEquals(3, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveSheetIndexTooHigh(): void
|
public function testRemoveSheetIndexTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->removeSheetByIndex(4);
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->removeSheetByIndex(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveSheetNoAdjustActive(): void
|
public function testRemoveSheetNoAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(1);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(1);
|
||||||
$this->object->removeSheetByIndex(2);
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(2);
|
||||||
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveSheetAdjustActive(): void
|
public function testRemoveSheetAdjustActive(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
$this->object->removeSheetByIndex(1);
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(1);
|
||||||
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSheetIndexTooHigh(): void
|
public function testGetSheetIndexTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->getSheet(4);
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->getSheet(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetIndexNonExistent(): void
|
public function testGetIndexNonExistent(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
|
$this->expectException(ssException::class);
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet4');
|
$sheet->setTitle('someSheet4');
|
||||||
$this->object->getIndex($sheet);
|
$spreadsheet->getIndex($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetIndexByName(): void
|
public function testSetIndexByName(): void
|
||||||
{
|
{
|
||||||
$this->object->setIndexByName('someSheet1', 1);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals('someSheet2', $this->object->getSheet(0)->getTitle());
|
$spreadsheet->setIndexByName('someSheet1', 1);
|
||||||
self::assertEquals('someSheet1', $this->object->getSheet(1)->getTitle());
|
self::assertEquals('someSheet2', $spreadsheet->getSheet(0)->getTitle());
|
||||||
self::assertEquals('someSheet 3', $this->object->getSheet(2)->getTitle());
|
self::assertEquals('someSheet1', $spreadsheet->getSheet(1)->getTitle());
|
||||||
|
self::assertEquals('someSheet 3', $spreadsheet->getSheet(2)->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRemoveAllSheets(): void
|
public function testRemoveAllSheets(): void
|
||||||
{
|
{
|
||||||
$this->object->setActiveSheetIndex(2);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
self::assertEquals(2, $this->object->getActiveSheetIndex());
|
$spreadsheet->setActiveSheetIndex(2);
|
||||||
$this->object->removeSheetByIndex(0);
|
self::assertEquals(2, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(0);
|
||||||
$this->object->removeSheetByIndex(0);
|
self::assertEquals(1, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(0, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(0);
|
||||||
$this->object->removeSheetByIndex(0);
|
self::assertEquals(0, $spreadsheet->getActiveSheetIndex());
|
||||||
self::assertEquals(-1, $this->object->getActiveSheetIndex());
|
$spreadsheet->removeSheetByIndex(0);
|
||||||
|
self::assertEquals(-1, $spreadsheet->getActiveSheetIndex());
|
||||||
$sheet = new Worksheet();
|
$sheet = new Worksheet();
|
||||||
$sheet->setTitle('someSheet4');
|
$sheet->setTitle('someSheet4');
|
||||||
$this->object->addSheet($sheet);
|
$spreadsheet->addSheet($sheet);
|
||||||
self::assertEquals(0, $this->object->getActiveSheetIndex());
|
self::assertEquals(0, $spreadsheet->getActiveSheetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBug1735(): void
|
public function testBug1735(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet1 = new Spreadsheet();
|
||||||
$spreadsheet->createSheet()->setTitle('addedsheet');
|
$spreadsheet1->createSheet()->setTitle('addedsheet');
|
||||||
$spreadsheet->setActiveSheetIndex(1);
|
$spreadsheet1->setActiveSheetIndex(1);
|
||||||
$spreadsheet->removeSheetByIndex(0);
|
$spreadsheet1->removeSheetByIndex(0);
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $spreadsheet1->getActiveSheet();
|
||||||
self::assertEquals('addedsheet', $sheet->getTitle());
|
self::assertEquals('addedsheet', $sheet->getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetActiveSheetIndexTooHigh(): void
|
public function testSetActiveSheetIndexTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->setActiveSheetIndex(4);
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->setActiveSheetIndex(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetActiveSheetNoSuchName(): void
|
public function testSetActiveSheetNoSuchName(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$this->object->setActiveSheetIndexByName('unknown');
|
$this->expectException(ssException::class);
|
||||||
|
$spreadsheet->setActiveSheetIndexByName('unknown');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddExternal(): void
|
public function testAddExternal(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = $this->getSpreadsheet();
|
||||||
$sheet = $spreadsheet->createSheet()->setTitle('someSheet19');
|
$spreadsheet1 = new Spreadsheet();
|
||||||
|
$sheet = $spreadsheet1->createSheet()->setTitle('someSheet19');
|
||||||
$sheet->getCell('A1')->setValue(1);
|
$sheet->getCell('A1')->setValue(1);
|
||||||
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
$sheet->getCell('B1')->getStyle()->getFont()->setSuperscript(true);
|
$sheet->getCell('B1')->getStyle()->getFont()->setSuperscript(true);
|
||||||
$sheet->getCell('C1')->getStyle()->getFont()->setSubscript(true);
|
$sheet->getCell('C1')->getStyle()->getFont()->setSubscript(true);
|
||||||
self::assertCount(4, $spreadsheet->getCellXfCollection());
|
self::assertCount(4, $spreadsheet1->getCellXfCollection());
|
||||||
self::assertEquals(1, $sheet->getCell('A1')->getXfIndex());
|
self::assertEquals(1, $sheet->getCell('A1')->getXfIndex());
|
||||||
$this->object->getActiveSheet()->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$spreadsheet->getActiveSheet()->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
self::assertCount(2, $this->object->getCellXfCollection());
|
self::assertCount(2, $spreadsheet->getCellXfCollection());
|
||||||
$sheet3 = $this->object->addExternalSheet($sheet);
|
$sheet3 = $spreadsheet->addExternalSheet($sheet);
|
||||||
self::assertCount(6, $this->object->getCellXfCollection());
|
self::assertCount(6, $spreadsheet->getCellXfCollection());
|
||||||
self::assertEquals('someSheet19', $sheet3->getTitle());
|
self::assertEquals('someSheet19', $sheet3->getTitle());
|
||||||
self::assertEquals(1, $sheet3->getCell('A1')->getValue());
|
self::assertEquals(1, $sheet3->getCell('A1')->getValue());
|
||||||
self::assertTrue($sheet3->getCell('A1')->getStyle()->getFont()->getBold());
|
self::assertTrue($sheet3->getCell('A1')->getStyle()->getFont()->getBold());
|
||||||
|
|
@ -181,17 +210,17 @@ class SpreadsheetTest extends TestCase
|
||||||
|
|
||||||
public function testAddExternalDuplicateName(): void
|
public function testAddExternalDuplicateName(): void
|
||||||
{
|
{
|
||||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
$this->expectException(ssException::class);
|
||||||
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->createSheet()->setTitle('someSheet1');
|
$sheet = $spreadsheet->createSheet()->setTitle('someSheet1');
|
||||||
$sheet->getCell('A1')->setValue(1);
|
$sheet->getCell('A1')->setValue(1);
|
||||||
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
$this->object->addExternalSheet($sheet);
|
$spreadsheet->addExternalSheet($sheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAddExternalColumnDimensionStyles(): void
|
public function testAddExternalColumnDimensionStyles(): void
|
||||||
{
|
{
|
||||||
$spreadsheet1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet1 = new Spreadsheet();
|
||||||
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
||||||
|
|
@ -200,7 +229,7 @@ class SpreadsheetTest extends TestCase
|
||||||
self::assertEquals(1, $index);
|
self::assertEquals(1, $index);
|
||||||
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
||||||
|
|
||||||
$spreadsheet2 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet2 = new Spreadsheet();
|
||||||
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
||||||
$sheet2->getCell('A1')->setValue(1);
|
$sheet2->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
|
|
@ -220,7 +249,7 @@ class SpreadsheetTest extends TestCase
|
||||||
|
|
||||||
public function testAddExternalRowDimensionStyles(): void
|
public function testAddExternalRowDimensionStyles(): void
|
||||||
{
|
{
|
||||||
$spreadsheet1 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet1 = new Spreadsheet();
|
||||||
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
$sheet1 = $spreadsheet1->createSheet()->setTitle('sheetWithColumnDimension');
|
||||||
$sheet1->getCell('A1')->setValue(1);
|
$sheet1->getCell('A1')->setValue(1);
|
||||||
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
$sheet1->getCell('A1')->getStyle()->getFont()->setItalic(true);
|
||||||
|
|
@ -229,7 +258,7 @@ class SpreadsheetTest extends TestCase
|
||||||
self::assertEquals(1, $index);
|
self::assertEquals(1, $index);
|
||||||
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
self::assertCount(2, $spreadsheet1->getCellXfCollection());
|
||||||
|
|
||||||
$spreadsheet2 = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
$spreadsheet2 = new Spreadsheet();
|
||||||
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
$sheet2 = $spreadsheet2->createSheet()->setTitle('sheetWithTwoStyles');
|
||||||
$sheet2->getCell('A1')->setValue(1);
|
$sheet2->getCell('A1')->setValue(1);
|
||||||
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
$sheet2->getCell('A1')->getStyle()->getFont()->setBold(true);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpSpreadsheetTests\Style;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Html;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use ZipArchive;
|
||||||
|
|
||||||
|
class AlignmentMiddleTest extends TestCase
|
||||||
|
{
|
||||||
|
/** @var ?Spreadsheet */
|
||||||
|
private $spreadsheet;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $outputFileName = '';
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
if ($this->spreadsheet !== null) {
|
||||||
|
$this->spreadsheet->disconnectWorksheets();
|
||||||
|
$this->spreadsheet = null;
|
||||||
|
}
|
||||||
|
if ($this->outputFileName !== '') {
|
||||||
|
unlink($this->outputFileName);
|
||||||
|
$this->outputFileName = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCenterWriteHtml(): void
|
||||||
|
{
|
||||||
|
// Html Writer changes vertical align center to middle
|
||||||
|
$this->spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
|
$sheet->getCell('A1')->setValue('Cell1');
|
||||||
|
$sheet->getStyle('A1')
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_CENTER);
|
||||||
|
$writer = new HTML($this->spreadsheet);
|
||||||
|
$html = $writer->generateHtmlAll();
|
||||||
|
self::assertStringContainsString('vertical-align:middle', $html);
|
||||||
|
self::assertStringNotContainsString('vertical-align:center', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCenterWriteXlsx(): void
|
||||||
|
{
|
||||||
|
// Xlsx Writer uses vertical align center unchanged
|
||||||
|
$this->spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
|
$sheet->getCell('A1')->setValue('Cell1');
|
||||||
|
$sheet->getStyle('A1')
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical(Alignment::VERTICAL_CENTER);
|
||||||
|
$this->outputFileName = File::temporaryFilename();
|
||||||
|
$writer = new Xlsx($this->spreadsheet);
|
||||||
|
$writer->save($this->outputFileName);
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$zip->open($this->outputFileName);
|
||||||
|
$html = $zip->getFromName('xl/styles.xml');
|
||||||
|
$zip->close();
|
||||||
|
self::assertStringContainsString('vertical="center"', $html);
|
||||||
|
self::assertStringNotContainsString('vertical="middle"', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCenterWriteXlsx2(): void
|
||||||
|
{
|
||||||
|
// Xlsx Writer changes vertical align middle to center
|
||||||
|
$this->spreadsheet = new Spreadsheet();
|
||||||
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
|
$sheet->getCell('A1')->setValue('Cell1');
|
||||||
|
$sheet->getStyle('A1')
|
||||||
|
->getAlignment()
|
||||||
|
->setVertical('middle');
|
||||||
|
$this->outputFileName = File::temporaryFilename();
|
||||||
|
$writer = new Xlsx($this->spreadsheet);
|
||||||
|
$writer->save($this->outputFileName);
|
||||||
|
$zip = new ZipArchive();
|
||||||
|
$zip->open($this->outputFileName);
|
||||||
|
$html = $zip->getFromName('xl/styles.xml');
|
||||||
|
$zip->close();
|
||||||
|
self::assertStringContainsString('vertical="center"', $html);
|
||||||
|
self::assertStringNotContainsString('vertical="middle"', $html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -9,10 +9,21 @@ use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class AlignmentTest extends TestCase
|
class AlignmentTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/** @var ?Spreadsheet */
|
||||||
|
private $spreadsheet;
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
if ($this->spreadsheet !== null) {
|
||||||
|
$this->spreadsheet->disconnectWorksheets();
|
||||||
|
$this->spreadsheet = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testAlignment(): void
|
public function testAlignment(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new Spreadsheet();
|
$this->spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
$cell1 = $sheet->getCell('A1');
|
$cell1 = $sheet->getCell('A1');
|
||||||
$cell1->setValue('Cell1');
|
$cell1->setValue('Cell1');
|
||||||
$cell1->getStyle()->getAlignment()->setTextRotation(45);
|
$cell1->getStyle()->getAlignment()->setTextRotation(45);
|
||||||
|
|
@ -31,8 +42,8 @@ class AlignmentTest extends TestCase
|
||||||
public function testRotationTooHigh(): void
|
public function testRotationTooHigh(): void
|
||||||
{
|
{
|
||||||
$this->expectException(PhpSpreadsheetException::class);
|
$this->expectException(PhpSpreadsheetException::class);
|
||||||
$spreadsheet = new Spreadsheet();
|
$this->spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
$cell1 = $sheet->getCell('A1');
|
$cell1 = $sheet->getCell('A1');
|
||||||
$cell1->setValue('Cell1');
|
$cell1->setValue('Cell1');
|
||||||
$cell1->getStyle()->getAlignment()->setTextRotation(91);
|
$cell1->getStyle()->getAlignment()->setTextRotation(91);
|
||||||
|
|
@ -42,8 +53,8 @@ class AlignmentTest extends TestCase
|
||||||
public function testRotationTooLow(): void
|
public function testRotationTooLow(): void
|
||||||
{
|
{
|
||||||
$this->expectException(PhpSpreadsheetException::class);
|
$this->expectException(PhpSpreadsheetException::class);
|
||||||
$spreadsheet = new Spreadsheet();
|
$this->spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
$cell1 = $sheet->getCell('A1');
|
$cell1 = $sheet->getCell('A1');
|
||||||
$cell1->setValue('Cell1');
|
$cell1->setValue('Cell1');
|
||||||
$cell1->getStyle()->getAlignment()->setTextRotation(-91);
|
$cell1->getStyle()->getAlignment()->setTextRotation(-91);
|
||||||
|
|
@ -52,8 +63,8 @@ class AlignmentTest extends TestCase
|
||||||
|
|
||||||
public function testHorizontal(): void
|
public function testHorizontal(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new Spreadsheet();
|
$this->spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
$cell1 = $sheet->getCell('A1');
|
$cell1 = $sheet->getCell('A1');
|
||||||
$cell1->setValue('X');
|
$cell1->setValue('X');
|
||||||
$cell1->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)->setIndent(1);
|
$cell1->getStyle()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT)->setIndent(1);
|
||||||
|
|
@ -74,8 +85,8 @@ class AlignmentTest extends TestCase
|
||||||
|
|
||||||
public function testReadOrder(): void
|
public function testReadOrder(): void
|
||||||
{
|
{
|
||||||
$spreadsheet = new Spreadsheet();
|
$this->spreadsheet = new Spreadsheet();
|
||||||
$sheet = $spreadsheet->getActiveSheet();
|
$sheet = $this->spreadsheet->getActiveSheet();
|
||||||
$cell1 = $sheet->getCell('A1');
|
$cell1 = $sheet->getCell('A1');
|
||||||
$cell1->setValue('ABC');
|
$cell1->setValue('ABC');
|
||||||
$cell1->getStyle()->getAlignment()->setReadOrder(0);
|
$cell1->getStyle()->getAlignment()->setReadOrder(0);
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
namespace PhpOffice\PhpSpreadsheetTests\Style\ConditionalFormatting;
|
namespace PhpOffice\PhpSpreadsheetTests\Style\ConditionalFormatting;
|
||||||
|
|
||||||
|
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Exception as ssException;
|
||||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\CellMatcher;
|
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\CellMatcher;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class CellMatcherTest extends TestCase
|
class CellMatcherTest extends TestCase
|
||||||
|
|
@ -30,18 +33,26 @@ class CellMatcherTest extends TestCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function confirmString(Worksheet $worksheet, Cell $cell, string $cellAddress): string
|
||||||
|
{
|
||||||
|
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate()) ?? '';
|
||||||
|
if ($cfRange === '') {
|
||||||
|
self::fail("{$cellAddress} is not in a Conditional Format range");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cfRange;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider basicCellIsComparisonDataProvider
|
* @dataProvider basicCellIsComparisonDataProvider
|
||||||
*/
|
*/
|
||||||
public function testBasicCellIsComparison(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testBasicCellIsComparison(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "{$cellAddress} is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -83,18 +94,35 @@ class CellMatcherTest extends TestCase
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNotInRange(): void
|
||||||
|
{
|
||||||
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
|
$sheetname = 'cellIs Comparison';
|
||||||
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
|
$cell = $worksheet->getCell('J20');
|
||||||
|
|
||||||
|
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
||||||
|
self::assertNull($cfRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnknownSheet(): void
|
||||||
|
{
|
||||||
|
$this->expectException(ssException::class);
|
||||||
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
|
$sheetname = 'cellIs Comparisonxxx';
|
||||||
|
$this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider rangeCellIsComparisonDataProvider
|
* @dataProvider rangeCellIsComparisonDataProvider
|
||||||
*/
|
*/
|
||||||
public function testRangeCellIsComparison(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testRangeCellIsComparison(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -132,12 +160,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testCellIsMultipleExpression(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testCellIsMultipleExpression(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -168,12 +194,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testCellIsExpression(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testCellIsExpression(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -214,12 +238,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testTextExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testTextExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -324,12 +346,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testBlankExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testBlankExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -357,12 +377,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testErrorExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testErrorExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -389,12 +407,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testDateOccurringExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testDateOccurringExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -433,12 +449,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testDuplicatesExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
public function testDuplicatesExpressions(string $sheetname, string $cellAddress, array $expectedMatches): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::AssertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyles = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
@ -469,12 +483,10 @@ class CellMatcherTest extends TestCase
|
||||||
public function testCrossWorksheetExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
public function testCrossWorksheetExpressions(string $sheetname, string $cellAddress, bool $expectedMatch): void
|
||||||
{
|
{
|
||||||
$this->spreadsheet = $this->loadSpreadsheet();
|
$this->spreadsheet = $this->loadSpreadsheet();
|
||||||
$worksheet = $this->spreadsheet->getSheetByName($sheetname);
|
$worksheet = $this->spreadsheet->getSheetByNameOrThrow($sheetname);
|
||||||
self::assertNotNull($worksheet, "$sheetname not found in test workbook");
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $this->confirmString($worksheet, $cell, $cellAddress);
|
||||||
self::assertNotNull($cfRange, "$cellAddress is not in a Conditional Format range");
|
|
||||||
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
$cfStyle = $worksheet->getConditionalStyles($cell->getCoordinate());
|
||||||
|
|
||||||
$matcher = new CellMatcher($cell, $cfRange);
|
$matcher = new CellMatcher($cell, $cfRange);
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ class WizardFactoryTest extends TestCase
|
||||||
/**
|
/**
|
||||||
* @dataProvider basicWizardFactoryProvider
|
* @dataProvider basicWizardFactoryProvider
|
||||||
*
|
*
|
||||||
* @param class-string<object> $expectedWizard
|
* @psalm-param class-string<object> $expectedWizard
|
||||||
*/
|
*/
|
||||||
public function testBasicWizardFactory(string $ruleType, $expectedWizard): void
|
public function testBasicWizardFactory(string $ruleType, string $expectedWizard): void
|
||||||
{
|
{
|
||||||
$wizard = $this->wizardFactory->newRule($ruleType);
|
$wizard = $this->wizardFactory->newRule($ruleType);
|
||||||
self::assertInstanceOf($expectedWizard, $wizard);
|
self::assertInstanceOf($expectedWizard, $wizard);
|
||||||
|
|
@ -54,10 +54,7 @@ class WizardFactoryTest extends TestCase
|
||||||
$filename = 'tests/data/Style/ConditionalFormatting/CellMatcher.xlsx';
|
$filename = 'tests/data/Style/ConditionalFormatting/CellMatcher.xlsx';
|
||||||
$reader = IOFactory::createReader('Xlsx');
|
$reader = IOFactory::createReader('Xlsx');
|
||||||
$spreadsheet = $reader->load($filename);
|
$spreadsheet = $reader->load($filename);
|
||||||
$worksheet = $spreadsheet->getSheetByName($sheetName);
|
$worksheet = $spreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
if ($worksheet === null) {
|
|
||||||
self::markTestSkipped("{$sheetName} not found in test workbook");
|
|
||||||
}
|
|
||||||
$cell = $worksheet->getCell($cellAddress);
|
$cell = $worksheet->getCell($cellAddress);
|
||||||
|
|
||||||
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
$cfRange = $worksheet->getConditionalRange($cell->getCoordinate());
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class NumberFormatTest extends TestCase
|
||||||
public function testFormatValueWithMask($expectedResult, ...$args): void
|
public function testFormatValueWithMask($expectedResult, ...$args): void
|
||||||
{
|
{
|
||||||
$result = NumberFormat::toFormattedString(...$args);
|
$result = NumberFormat::toFormattedString(...$args);
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertSame($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function providerNumberFormat(): array
|
public function providerNumberFormat(): array
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class VisibilityTest extends AbstractFunctional
|
||||||
|
|
||||||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xls');
|
||||||
foreach ($visibleSheets as $sheetName => $visibility) {
|
foreach ($visibleSheets as $sheetName => $visibility) {
|
||||||
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByName($sheetName) ?? new Worksheet();
|
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,19 +77,15 @@ class UnparsedDataCloneTest extends TestCase
|
||||||
$reader1 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader1 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$spreadsheet1 = $reader1->load($resultFilename1);
|
$spreadsheet1 = $reader1->load($resultFilename1);
|
||||||
unlink($resultFilename1);
|
unlink($resultFilename1);
|
||||||
$sheet1c = $spreadsheet1->getSheetByName('Clone');
|
$sheet1c = $spreadsheet1->getSheetByNameOrThrow('Clone');
|
||||||
self::assertNotNull($sheet1c);
|
$sheet1o = $spreadsheet1->getSheetByNameOrThrow('Original');
|
||||||
$sheet1o = $spreadsheet1->getSheetByName('Original');
|
|
||||||
self::assertNotNull($sheet1o);
|
|
||||||
|
|
||||||
$writer->save($resultFilename2);
|
$writer->save($resultFilename2);
|
||||||
$reader2 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
$reader2 = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
|
||||||
$spreadsheet2 = $reader2->load($resultFilename2);
|
$spreadsheet2 = $reader2->load($resultFilename2);
|
||||||
unlink($resultFilename2);
|
unlink($resultFilename2);
|
||||||
$sheet2c = $spreadsheet2->getSheetByName('Clone');
|
$sheet2c = $spreadsheet2->getSheetByNameOrThrow('Clone');
|
||||||
self::assertNotNull($sheet2c);
|
$sheet2o = $spreadsheet2->getSheetByNameOrThrow('Original');
|
||||||
$sheet2o = $spreadsheet2->getSheetByName('Original');
|
|
||||||
self::assertNotNull($sheet2o);
|
|
||||||
|
|
||||||
self::assertEquals($spreadsheet1->getSheetCount(), $spreadsheet2->getSheetCount());
|
self::assertEquals($spreadsheet1->getSheetCount(), $spreadsheet2->getSheetCount());
|
||||||
self::assertCount(1, $sheet1c->getDrawingCollection());
|
self::assertCount(1, $sheet1c->getDrawingCollection());
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ class VisibilityTest extends AbstractFunctional
|
||||||
|
|
||||||
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
|
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx');
|
||||||
foreach ($visibleSheets as $sheetName => $visibility) {
|
foreach ($visibleSheets as $sheetName => $visibility) {
|
||||||
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByName($sheetName) ?? new Worksheet();
|
$reloadedWorksheet = $reloadedSpreadsheet->getSheetByNameOrThrow($sheetName);
|
||||||
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
self::assertSame($visibility, $reloadedWorksheet->getSheetState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,4 +83,5 @@ return [
|
||||||
-21000,
|
-21000,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'no arguments' => ['exception'],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -146,13 +146,13 @@ return [
|
||||||
'#,###',
|
'#,###',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
12,
|
'12',
|
||||||
12000,
|
12000,
|
||||||
'#,',
|
'#,',
|
||||||
],
|
],
|
||||||
// Scaling test
|
// Scaling test
|
||||||
[
|
[
|
||||||
12.199999999999999,
|
'12.2',
|
||||||
12200000,
|
12200000,
|
||||||
'0.0,,',
|
'0.0,,',
|
||||||
],
|
],
|
||||||
|
|
@ -1486,4 +1486,9 @@ return [
|
||||||
'-1111.119',
|
'-1111.119',
|
||||||
NumberFormat::FORMAT_ACCOUNTING_EUR,
|
NumberFormat::FORMAT_ACCOUNTING_EUR,
|
||||||
],
|
],
|
||||||
|
'issue 1929' => ['(79.3%)', -0.793, '#,##0.0%;(#,##0.0%)'],
|
||||||
|
'percent without leading 0' => ['6.2%', 0.062, '##.0%'],
|
||||||
|
'percent with leading 0' => ['06.2%', 0.062, '00.0%'],
|
||||||
|
'percent lead0 no decimal' => ['06%', 0.062, '00%'],
|
||||||
|
'percent nolead0 no decimal' => ['6%', 0.062, '##%'],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue