Merge branch 'master' into moredatefilter

This commit is contained in:
oleibman 2021-06-14 20:13:36 -07:00 committed by GitHub
commit 9b6e4f9bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 1225 additions and 242 deletions

View File

@ -9,7 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Added ### Added
- Nothing. - Support for passing flags in the Reader `load()` and Writer `save()`methods, and through the IOFactory, to set behaviours. [PR #2136](https://github.com/PHPOffice/PhpSpreadsheet/pull/2136)
- See [documentation](https://phpspreadsheet.readthedocs.io/en/latest/topics/reading-and-writing-to-file/) for details
- More flexibility in the StringValueBinder to determine what datatypes should be treated as strings [PR #2138](https://github.com/PHPOffice/PhpSpreadsheet/pull/2138)
- Helper class for conversion between css size Units of measure (`px`, `pt`, `pc`, `in`, `cm`, `mm`). [PR #2152](https://github.com/PHPOffice/PhpSpreadsheet/issues/2145)
- Allow Row height and Column Width to be set using different units of measure (`px`, `pt`, `pc`, `in`, `cm`, `mm`), rather than only in points or MS Excel column width units. [PR #2152](https://github.com/PHPOffice/PhpSpreadsheet/issues/2145)
### Changed ### Changed
@ -25,7 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed ### Fixed
- Nothing. - Xls Reader changing grey background to black in Excel template [Issue #2147](Changing grey background to black in Excel template) [PR #2156](https://github.com/PHPOffice/PhpSpreadsheet/pull/2156)
- Column width and Row height styles in the Html Reader when the value includes a unit of measure. [Issue #2145](https://github.com/PHPOffice/PhpSpreadsheet/issues/2145).
## 1.18.0 - 2021-05-31 ## 1.18.0 - 2021-05-31

View File

@ -110,6 +110,11 @@ values beginning with `=` will be converted to a formula. Strings that
aren't numeric, or that don't begin with a leading `=` will be treated aren't numeric, or that don't begin with a leading `=` will be treated
as genuine string values. as genuine string values.
Note that a numeric string that begins with a leading zero (that isn't
immediately followed by a decimal separator) will not be converted to a
numeric, so values like phone numbers (e.g. `01615991375``will remain as
strings).
This "conversion" is handled by a cell "value binder", and you can write This "conversion" is handled by a cell "value binder", and you can write
custom "value binders" to change the behaviour of these "conversions". custom "value binders" to change the behaviour of these "conversions".
The standard PhpSpreadsheet package also provides an "advanced value The standard PhpSpreadsheet package also provides an "advanced value
@ -138,8 +143,10 @@ Formats handled by the advanced value binder include:
- When strings contain a newline character (`\n`), then the cell styling is - When strings contain a newline character (`\n`), then the cell styling is
set to wrap. set to wrap.
You can read more about value binders later in this section of the Basically, it attempts to mimic the behaviour of the MS Excel GUI.
documentation.
You can read more about value binders [later in this section of the
documentation](#using-value-binders-to-facilitate-data-entry).
### Setting a formula in a Cell ### Setting a formula in a Cell
@ -551,8 +558,27 @@ $spreadsheet->getActiveSheet()->setCellValue('A5', 'Date/time value:');
$spreadsheet->getActiveSheet()->setCellValue('B5', '21 December 1983'); $spreadsheet->getActiveSheet()->setCellValue('B5', '21 December 1983');
``` ```
**Creating your own value binder is easy.** When advanced value binding Alternatively, a `\PhpOffice\PhpSpreadsheet\Cell\StringValueBinder` class is available
is required, you can implement the if you want to preserve all content as strings. This might be appropriate if you
`\PhpOffice\PhpSpreadsheet\Cell\IValueBinder` interface or extend the were loading a file containing values that could be interpreted as numbers (e.g. numbers
with leading sign such as international phone numbers like `+441615579382`), but that
should be retained as strings (non-international phone numbers with leading zeroes are
already maintained as strings).
By default, the StringValueBinder will cast any datatype passed to it into a string. However, there are a number of settings which allow you to specify that certain datatypes shouldn't be cast to strings, but left "as is":
```php
// Set value binder
$stringValueBinder = new \PhpOffice\PhpSpreadsheet\Cell\StringValueBinder();
$stringValueBinder->setNumericConversion(false)
->setBooleanConversion(false)
->setNullConversion(false)
->setFormulaConversion(false);
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $stringValueBinder );
```
**Creating your own value binder is relatively straightforward.** When more specialised
value binding is required, you can implement the
`\PhpOffice\PhpSpreadsheet\Cell\IValueBinder` interface or extend the existing
`\PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder` or `\PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder` or
`\PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder` classes. `\PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder` classes.

View File

@ -1,8 +1,7 @@
# Reading and writing to file # Reading and writing to file
As you already know from the [architecture](./architecture.md#readers-and-writers), As you already know from the [architecture](./architecture.md#readers-and-writers),
reading and writing to a reading and writing to a persisted storage is not possible using the base PhpSpreadsheet classes.
persisted storage is not possible using the base PhpSpreadsheet classes.
For this purpose, PhpSpreadsheet provides readers and writers, which are For this purpose, PhpSpreadsheet provides readers and writers, which are
implementations of `\PhpOffice\PhpSpreadsheet\Reader\IReader` and implementations of `\PhpOffice\PhpSpreadsheet\Reader\IReader` and
`\PhpOffice\PhpSpreadsheet\Writer\IWriter`. `\PhpOffice\PhpSpreadsheet\Writer\IWriter`.
@ -892,8 +891,7 @@ class My_Custom_TCPDF_Writer extends \PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf
#### Writing a spreadsheet #### Writing a spreadsheet
Once you have identified the Renderer that you wish to use for PDF Once you have identified the Renderer that you wish to use for PDF generation, you can write a .pdf file using the following code:
generation, you can write a .pdf file using the following code:
```php ```php
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet); $writer = new \PhpOffice\PhpSpreadsheet\Writer\Pdf\Mpdf($spreadsheet);
@ -905,8 +903,7 @@ first worksheet by default.
#### Write all worksheets #### Write all worksheets
PDF files can contain one or more worksheets. If you want to write all PDF files can contain one or more worksheets. If you want to write all sheets into a single PDF file, use the following code:
sheets into a single PDF file, use the following code:
```php ```php
$writer->writeAllSheets(); $writer->writeAllSheets();
@ -1020,3 +1017,64 @@ $spreadhseet = $reader->loadFromString($secondHtmlString, $spreadsheet);
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls'); $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('write.xls'); $writer->save('write.xls');
``` ```
## Reader/Writer Flags
Some Readers and Writers support special "Feature Flags" that need to be explicitly enabled.
An example of this is Charts in a spreadsheet. By default, when you load a spreadsheet that contains Charts, the charts will not be loaded. If all you want to do is read the data in the spreadsheet, then loading charts is an overhead for both speed of loading and memory usage.
However, there are times when you may want to load any charts in the spreadsheet as well as the data. To do so, you need to tell the Reader explicitly to include Charts.
```php
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile("05featuredemo.xlsx");
$reader->setIncludeCharts(true);
$reader->load("spreadsheetWithCharts.xlsx");
```
Alternatively, you can specify this in the call to load the spreadsheet:
```php
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReaderForFile("spreadsheetWithCharts.xlsx");
$reader->load("spreadsheetWithCharts.xlsx", $reader::LOAD_WITH_CHARTS);
```
If you wish to use the IOFactory `load()` method rather than instantiating a specific Reader, then you can still pass these flags.
```php
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load("spreadsheetWithCharts.xlsx", \PhpOffice\PhpSpreadsheet\Reader\IReader::LOAD_WITH_CHARTS);
```
Likewise, when saving a file using a Writer, loaded charts wil not be saved unless you explicitly tell the Writer to include them:
```php
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true);
$writer->save('mySavedFileWithCharts.xlsx');
```
As with the `load()` method, you can also pass flags in the `save()` method:
```php
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->save('mySavedFileWithCharts.xlsx', \PhpOffice\PhpSpreadsheet\Writer\IWriter::SAVE_WITH_CHARTS);
```
Currently, the only special "Feature Flag" that is supported in this way is the inclusion of Charts, and only for certain formats.
Readers | LOAD_WITH_CHARTS |
---------|------------------|
Xlsx | YES |
Xls | NO |
Xml | NO |
Ods | NO |
Gnumeric | NO |
Html | N/A |
Slk | N/A |
Csv | N/A |
Writers | SAVE_WITH_CHARTS |
--------|------------------|
Xlsx | YES |
Xls | NO |
Ods | NO |
Html | YES |
Pdf | YES |
Csv | N/A |

View File

@ -1122,6 +1122,16 @@ A column's width can be set using the following code:
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(12); $spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(12);
``` ```
If you want to set a column width using a different unit of measure,
then you can do so by telling PhpSpreadsheet what UoM the width value
that you are setting is measured in.
Valid units are `pt` (points), `px` (pixels), `pc` (pica), `in` (inches),
`cm` (centimeters) and `mm` (millimeters).
```php
$spreadsheet->getActiveSheet()->getColumnDimension('D')->setWidth(120, 'pt');
```
If you want PhpSpreadsheet to perform an automatic width calculation, If you want PhpSpreadsheet to perform an automatic width calculation,
use the following code. PhpSpreadsheet will approximate the column with use the following code. PhpSpreadsheet will approximate the column with
to the width of the widest column value. to the width of the widest column value.
@ -1207,6 +1217,16 @@ Excel measures row height in points, where 1 pt is 1/72 of an inch (or
about 0.35mm). The default value is 12.75 pts; and the permitted range about 0.35mm). The default value is 12.75 pts; and the permitted range
of values is between 0 and 409 pts, where 0 pts is a hidden row. of values is between 0 and 409 pts, where 0 pts is a hidden row.
If you want to set a row height using a different unit of measure,
then you can do so by telling PhpSpreadsheet what UoM the height value
that you are setting is measured in.
Valid units are `pt` (points), `px` (pixels), `pc` (pica), `in` (inches),
`cm` (centimeters) and `mm` (millimeters).
```php
$spreadsheet->getActiveSheet()->getRowDimension('10')->setRowHeight(100, 'pt');
```
## Show/hide a row ## Show/hide a row
To set a worksheet''s row visibility, you can use the following code. To set a worksheet''s row visibility, you can use the following code.
@ -1560,6 +1580,20 @@ Default column width can be set using the following code:
$spreadsheet->getActiveSheet()->getDefaultColumnDimension()->setWidth(12); $spreadsheet->getActiveSheet()->getDefaultColumnDimension()->setWidth(12);
``` ```
Excel measures column width in its own proprietary units, based on the number
of characters that will be displayed in the default font.
If you want to set the default column width using a different unit of measure,
then you can do so by telling PhpSpreadsheet what UoM the width value
that you are setting is measured in.
Valid units are `pt` (points), `px` (pixels), `pc` (pica), `in` (inches),
`cm` (centimeters) and `mm` (millimeters).
```php
$spreadsheet->getActiveSheet()->getDefaultColumnDimension()->setWidth(400, 'pt');
```
and PhpSpreadsheet will handle the internal conversion.
## Setting the default row height ## Setting the default row height
Default row height can be set using the following code: Default row height can be set using the following code:
@ -1568,6 +1602,21 @@ Default row height can be set using the following code:
$spreadsheet->getActiveSheet()->getDefaultRowDimension()->setRowHeight(15); $spreadsheet->getActiveSheet()->getDefaultRowDimension()->setRowHeight(15);
``` ```
Excel measures row height in points, where 1 pt is 1/72 of an inch (or
about 0.35mm). The default value is 12.75 pts; and the permitted range
of values is between 0 and 409 pts, where 0 pts is a hidden row.
If you want to set a row height using a different unit of measure,
then you can do so by telling PhpSpreadsheet what UoM the height value
that you are setting is measured in.
Valid units are `pt` (points), `px` (pixels), `pc` (pica), `in` (inches),
`cm` (centimeters) and `mm` (millimeters).
```php
$spreadsheet->getActiveSheet()->getDefaultRowDimension()->setRowHeight(100, 'pt');
```
## Add a GD drawing to a worksheet ## Add a GD drawing to a worksheet
There might be a situation where you want to generate an in-memory image There might be a situation where you want to generate an in-memory image

View File

@ -2487,7 +2487,7 @@ parameters:
- -
message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#" message: "#^Parameter \\#3 \\$subject of function str_replace expects array\\|string, string\\|null given\\.$#"
count: 4 count: 2
path: src/PhpSpreadsheet/Reader/Html.php path: src/PhpSpreadsheet/Reader/Html.php
- -
@ -2775,11 +2775,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Reader/Xls.php path: src/PhpSpreadsheet/Reader/Xls.php
-
message: "#^Parameter \\#1 \\$value of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\MemoryDrawing\\:\\:setImageResource\\(\\) expects GdImage\\|resource, resource\\|false given\\.$#"
count: 1
path: src/PhpSpreadsheet/Reader/Xls.php
- -
message: "#^Parameter \\#1 \\$pValue of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\BaseDrawing\\:\\:setOffsetX\\(\\) expects int, float\\|int given\\.$#" message: "#^Parameter \\#1 \\$pValue of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\BaseDrawing\\:\\:setOffsetX\\(\\) expects int, float\\|int given\\.$#"
count: 1 count: 1
@ -4100,11 +4095,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Shared/Date.php path: src/PhpSpreadsheet/Shared/Date.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:pixelsToCellDimension\\(\\) should return int but returns float\\|int\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Drawing.php
- -
message: "#^Parameter \\#1 \\$fp of function fread expects resource, resource\\|false given\\.$#" message: "#^Parameter \\#1 \\$fp of function fread expects resource, resource\\|false given\\.$#"
count: 2 count: 2
@ -4240,11 +4230,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Shared/Font.php path: src/PhpSpreadsheet/Shared/Font.php
-
message: "#^Parameter \\#1 \\$pValue of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:pixelsToCellDimension\\(\\) expects int, float\\|int given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Font.php
- -
message: "#^Parameter \\#2 \\$pDefaultFont of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:pixelsToCellDimension\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font, PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null given\\.$#" message: "#^Parameter \\#2 \\$pDefaultFont of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:pixelsToCellDimension\\(\\) expects PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font, PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font\\|null given\\.$#"
count: 1 count: 1
@ -4860,16 +4845,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Shared/XMLWriter.php path: src/PhpSpreadsheet/Shared/XMLWriter.php
-
message: "#^Parameter \\#1 \\$pValue of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Drawing\\:\\:pointsToPixels\\(\\) expects int, float given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Xls.php
-
message: "#^Parameter \\#1 \\$fontSizeInPoints of static method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Font\\:\\:fontSizeToPixels\\(\\) expects int, float given\\.$#"
count: 1
path: src/PhpSpreadsheet/Shared/Xls.php
- -
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Spreadsheet\\:\\:\\$workbookViewVisibilityValues has no typehint specified\\.$#" message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Spreadsheet\\:\\:\\$workbookViewVisibilityValues has no typehint specified\\.$#"
count: 1 count: 1
@ -6215,11 +6190,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Writer/Html.php path: src/PhpSpreadsheet/Writer/Html.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\IWriter\\:\\:save\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Writer/IWriter.php
- -
message: "#^Negated boolean expression is always false\\.$#" message: "#^Negated boolean expression is always false\\.$#"
count: 1 count: 1

View File

@ -12,7 +12,9 @@ use PhpOffice\PhpSpreadsheet\ReferenceHelper;
use PhpOffice\PhpSpreadsheet\Shared; use PhpOffice\PhpSpreadsheet\Shared;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use ReflectionClassConstant;
use ReflectionMethod; use ReflectionMethod;
use ReflectionParameter;
class Calculation class Calculation
{ {
@ -4108,7 +4110,7 @@ class Calculation
// If we've a comma when we're expecting an operand, then what we actually have is a null operand; // If we've a comma when we're expecting an operand, then what we actually have is a null operand;
// so push a null onto the stack // so push a null onto the stack
if (($expectingOperand) || (!$expectingOperator)) { if (($expectingOperand) || (!$expectingOperator)) {
$output[] = ['type' => 'NULL Value', 'value' => self::$excelConstants['NULL'], 'reference' => null]; $output[] = ['type' => 'Empty Argument', 'value' => self::$excelConstants['NULL'], 'reference' => null];
} }
// make sure there was a function // make sure there was a function
$d = $stack->last(2); $d = $stack->last(2);
@ -4293,7 +4295,7 @@ class Calculation
++$index; ++$index;
} elseif ($opCharacter == ')') { // miscellaneous error checking } elseif ($opCharacter == ')') { // miscellaneous error checking
if ($expectingOperand) { if ($expectingOperand) {
$output[] = ['type' => 'NULL Value', 'value' => self::$excelConstants['NULL'], 'reference' => null]; $output[] = ['type' => 'Empty Argument', 'value' => self::$excelConstants['NULL'], 'reference' => null];
$expectingOperand = false; $expectingOperand = false;
$expectingOperator = true; $expectingOperator = true;
} else { } else {
@ -4773,7 +4775,7 @@ class Calculation
$functionName = $matches[1]; $functionName = $matches[1];
$argCount = $stack->pop(); $argCount = $stack->pop();
$argCount = $argCount['value']; $argCount = $argCount['value'];
if ($functionName != 'MKMATRIX') { if ($functionName !== 'MKMATRIX') {
$this->debugLog->writeDebugLog('Evaluating Function ', self::localeFunc($functionName), '() with ', (($argCount == 0) ? 'no' : $argCount), ' argument', (($argCount == 1) ? '' : 's')); $this->debugLog->writeDebugLog('Evaluating Function ', self::localeFunc($functionName), '() with ', (($argCount == 0) ? 'no' : $argCount), ' argument', (($argCount == 1) ? '' : 's'));
} }
if ((isset(self::$phpSpreadsheetFunctions[$functionName])) || (isset(self::$controlFunctions[$functionName]))) { // function if ((isset(self::$phpSpreadsheetFunctions[$functionName])) || (isset(self::$controlFunctions[$functionName]))) { // function
@ -4789,8 +4791,10 @@ class Calculation
$passByReference = isset(self::$controlFunctions[$functionName]['passByReference']); $passByReference = isset(self::$controlFunctions[$functionName]['passByReference']);
$passCellReference = isset(self::$controlFunctions[$functionName]['passCellReference']); $passCellReference = isset(self::$controlFunctions[$functionName]['passCellReference']);
} }
// get the arguments for this function // get the arguments for this function
$args = $argArrayVals = []; $args = $argArrayVals = [];
$emptyArguments = [];
for ($i = 0; $i < $argCount; ++$i) { for ($i = 0; $i < $argCount; ++$i) {
$arg = $stack->pop(); $arg = $stack->pop();
$a = $argCount - $i - 1; $a = $argCount - $i - 1;
@ -4801,18 +4805,19 @@ class Calculation
) { ) {
if ($arg['reference'] === null) { if ($arg['reference'] === null) {
$args[] = $cellID; $args[] = $cellID;
if ($functionName != 'MKMATRIX') { if ($functionName !== 'MKMATRIX') {
$argArrayVals[] = $this->showValue($cellID); $argArrayVals[] = $this->showValue($cellID);
} }
} else { } else {
$args[] = $arg['reference']; $args[] = $arg['reference'];
if ($functionName != 'MKMATRIX') { if ($functionName !== 'MKMATRIX') {
$argArrayVals[] = $this->showValue($arg['reference']); $argArrayVals[] = $this->showValue($arg['reference']);
} }
} }
} else { } else {
$emptyArguments[] = ($arg['type'] === 'Empty Argument');
$args[] = self::unwrapResult($arg['value']); $args[] = self::unwrapResult($arg['value']);
if ($functionName != 'MKMATRIX') { if ($functionName !== 'MKMATRIX') {
$argArrayVals[] = $this->showValue($arg['value']); $argArrayVals[] = $this->showValue($arg['value']);
} }
} }
@ -4820,13 +4825,18 @@ class Calculation
// Reverse the order of the arguments // Reverse the order of the arguments
krsort($args); krsort($args);
krsort($emptyArguments);
if ($argCount > 0) {
$args = $this->addDefaultArgumentValues($functionCall, $args, $emptyArguments);
}
if (($passByReference) && ($argCount == 0)) { if (($passByReference) && ($argCount == 0)) {
$args[] = $cellID; $args[] = $cellID;
$argArrayVals[] = $this->showValue($cellID); $argArrayVals[] = $this->showValue($cellID);
} }
if ($functionName != 'MKMATRIX') { if ($functionName !== 'MKMATRIX') {
if ($this->debugLog->getWriteDebugLog()) { if ($this->debugLog->getWriteDebugLog()) {
krsort($argArrayVals); krsort($argArrayVals);
$this->debugLog->writeDebugLog('Evaluating ', self::localeFunc($functionName), '( ', implode(self::$localeArgumentSeparator . ' ', Functions::flattenArray($argArrayVals)), ' )'); $this->debugLog->writeDebugLog('Evaluating ', self::localeFunc($functionName), '( ', implode(self::$localeArgumentSeparator . ' ', Functions::flattenArray($argArrayVals)), ' )');
@ -4845,7 +4855,7 @@ class Calculation
$result = call_user_func_array($functionCall, $args); $result = call_user_func_array($functionCall, $args);
if ($functionName != 'MKMATRIX') { if ($functionName !== 'MKMATRIX') {
$this->debugLog->writeDebugLog('Evaluation Result for ', self::localeFunc($functionName), '() function call is ', $this->showTypeDetails($result)); $this->debugLog->writeDebugLog('Evaluation Result for ', self::localeFunc($functionName), '() function call is ', $this->showTypeDetails($result));
} }
$stack->push('Value', self::wrapResult($result)); $stack->push('Value', self::wrapResult($result));
@ -4863,7 +4873,7 @@ class Calculation
} }
$this->debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->showTypeDetails(self::$excelConstants[$excelConstant])); $this->debugLog->writeDebugLog('Evaluating Constant ', $excelConstant, ' as ', $this->showTypeDetails(self::$excelConstants[$excelConstant]));
} elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == self::FORMULA_STRING_QUOTE) || ($token[0] == '#')) { } elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == self::FORMULA_STRING_QUOTE) || ($token[0] == '#')) {
$stack->push('Value', $token); $stack->push($tokenData['type'], $token, $tokenData['reference']);
if (isset($storeKey)) { if (isset($storeKey)) {
$branchStore[$storeKey] = $token; $branchStore[$storeKey] = $token;
} }
@ -5386,6 +5396,57 @@ class Calculation
return $returnValue; return $returnValue;
} }
private function addDefaultArgumentValues(array $functionCall, array $args, array $emptyArguments): array
{
$reflector = new ReflectionMethod(implode('::', $functionCall));
$methodArguments = $reflector->getParameters();
if (count($methodArguments) > 0) {
// Apply any defaults for empty argument values
foreach ($emptyArguments as $argumentId => $isArgumentEmpty) {
if ($isArgumentEmpty === true) {
$reflectedArgumentId = count($args) - $argumentId - 1;
if (
!array_key_exists($reflectedArgumentId, $methodArguments) ||
$methodArguments[$reflectedArgumentId]->isVariadic()
) {
break;
}
$args[$argumentId] = $this->getArgumentDefaultValue($methodArguments[$reflectedArgumentId]);
}
}
}
return $args;
}
/**
* @return null|mixed
*/
private function getArgumentDefaultValue(ReflectionParameter $methodArgument)
{
$defaultValue = null;
if ($methodArgument->isDefaultValueAvailable()) {
$defaultValue = $methodArgument->getDefaultValue();
if ($methodArgument->isDefaultValueConstant()) {
$constantName = $methodArgument->getDefaultValueConstantName() ?? '';
// read constant value
if (strpos($constantName, '::') !== false) {
[$className, $constantName] = explode('::', $constantName);
$constantReflector = new ReflectionClassConstant($className, $constantName);
return $constantReflector->getValue();
}
return constant($constantName);
}
}
return $defaultValue;
}
/** /**
* Add cell reference if needed while making sure that it is the last argument. * Add cell reference if needed while making sure that it is the last argument.
* *

View File

@ -27,7 +27,7 @@ abstract class DatabaseAbstract
*/ */
protected static function fieldExtract(array $database, $field): ?int protected static function fieldExtract(array $database, $field): ?int
{ {
$field = strtoupper(Functions::flattenSingleValue($field)); $field = strtoupper(Functions::flattenSingleValue($field ?? ''));
if ($field === '') { if ($field === '') {
return null; return null;
} }

View File

@ -37,7 +37,7 @@ class DateValue
{ {
$dti = new DateTimeImmutable(); $dti = new DateTimeImmutable();
$baseYear = SharedDateHelper::getExcelCalendar(); $baseYear = SharedDateHelper::getExcelCalendar();
$dateValue = trim(Functions::flattenSingleValue($dateValue), '"'); $dateValue = trim(Functions::flattenSingleValue($dateValue ?? ''), '"');
// Strip any ordinals because they're allowed in Excel (English only) // Strip any ordinals because they're allowed in Excel (English only)
$dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? ''; $dateValue = preg_replace('/(\d)(st|nd|rd|th)([ -\/])/Ui', '$1$3', $dateValue) ?? '';
// Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany) // Convert separators (/ . or space) to hyphens (should also handle dot used for ordinals in some countries, e.g. Denmark, Germany)

View File

@ -31,7 +31,7 @@ class TimeValue
*/ */
public static function fromString($timeValue) public static function fromString($timeValue)
{ {
$timeValue = trim(Functions::flattenSingleValue($timeValue), '"'); $timeValue = trim(Functions::flattenSingleValue($timeValue ?? ''), '"');
$timeValue = str_replace(['/', '.'], '-', $timeValue); $timeValue = str_replace(['/', '.'], '-', $timeValue);
$arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: []; $arraySplit = preg_split('/[\/:\-\s]/', $timeValue) ?: [];

View File

@ -26,7 +26,7 @@ class Extract
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
} }
return mb_substr($value, 0, $chars, 'UTF-8'); return mb_substr($value ?? '', 0, $chars, 'UTF-8');
} }
/** /**
@ -50,7 +50,7 @@ class Extract
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
} }
return mb_substr($value, --$start, $chars, 'UTF-8'); return mb_substr($value ?? '', --$start, $chars, 'UTF-8');
} }
/** /**
@ -72,6 +72,6 @@ class Extract
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
} }
return mb_substr($value, mb_strlen($value, 'UTF-8') - $chars, $chars, 'UTF-8'); return mb_substr($value ?? '', mb_strlen($value ?? '', 'UTF-8') - $chars, $chars, 'UTF-8');
} }
} }

View File

@ -20,7 +20,7 @@ class Text
$value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE(); $value = ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
} }
return mb_strlen($value, 'UTF-8'); return mb_strlen($value ?? '', 'UTF-8');
} }
/** /**

View File

@ -26,6 +26,7 @@ class DefaultValueBinder implements IValueBinder
if ($value instanceof DateTimeInterface) { if ($value instanceof DateTimeInterface) {
$value = $value->format('Y-m-d H:i:s'); $value = $value->format('Y-m-d H:i:s');
} elseif (!($value instanceof RichText)) { } elseif (!($value instanceof RichText)) {
// Attempt to cast any unexpected objects to string
$value = (string) $value; $value = (string) $value;
} }
} }
@ -57,11 +58,11 @@ class DefaultValueBinder implements IValueBinder
return DataType::TYPE_STRING; return DataType::TYPE_STRING;
} elseif ($value instanceof RichText) { } elseif ($value instanceof RichText) {
return DataType::TYPE_INLINE; return DataType::TYPE_INLINE;
} elseif (is_string($value) && $value[0] === '=' && strlen($value) > 1) { } elseif (is_string($value) && strlen($value) > 1 && $value[0] === '=') {
return DataType::TYPE_FORMULA; return DataType::TYPE_FORMULA;
} elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $value)) { } elseif (preg_match('/^[\+\-]?(\d+\\.?\d*|\d*\\.?\d+)([Ee][\-\+]?[0-2]?\d{1,3})?$/', $value)) {
$tValue = ltrim($value, '+-'); $tValue = ltrim($value, '+-');
if (is_string($value) && $tValue[0] === '0' && strlen($tValue) > 1 && $tValue[1] !== '.') { if (is_string($value) && strlen($tValue) > 1 && $tValue[0] === '0' && $tValue[1] !== '.') {
return DataType::TYPE_STRING; return DataType::TYPE_STRING;
} elseif ((strpos($value, '.') === false) && ($value > PHP_INT_MAX)) { } elseif ((strpos($value, '.') === false) && ($value > PHP_INT_MAX)) {
return DataType::TYPE_STRING; return DataType::TYPE_STRING;

View File

@ -2,28 +2,118 @@
namespace PhpOffice\PhpSpreadsheet\Cell; namespace PhpOffice\PhpSpreadsheet\Cell;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class StringValueBinder implements IValueBinder class StringValueBinder implements IValueBinder
{ {
/**
* @var bool
*/
protected $convertNull = true;
/**
* @var bool
*/
protected $convertBoolean = true;
/**
* @var bool
*/
protected $convertNumeric = true;
/**
* @var bool
*/
protected $convertFormula = true;
public function setNullConversion(bool $suppressConversion = false): self
{
$this->convertNull = $suppressConversion;
return $this;
}
public function setBooleanConversion(bool $suppressConversion = false): self
{
$this->convertBoolean = $suppressConversion;
return $this;
}
public function setNumericConversion(bool $suppressConversion = false): self
{
$this->convertNumeric = $suppressConversion;
return $this;
}
public function setFormulaConversion(bool $suppressConversion = false): self
{
$this->convertFormula = $suppressConversion;
return $this;
}
public function setConversionForAllValueTypes(bool $suppressConversion = false): self
{
$this->convertNull = $suppressConversion;
$this->convertBoolean = $suppressConversion;
$this->convertNumeric = $suppressConversion;
$this->convertFormula = $suppressConversion;
return $this;
}
/** /**
* Bind value to a cell. * Bind value to a cell.
* *
* @param Cell $cell Cell to bind value to * @param Cell $cell Cell to bind value to
* @param mixed $value Value to bind in cell * @param mixed $value Value to bind in cell
*
* @return bool
*/ */
public function bindValue(Cell $cell, $value) public function bindValue(Cell $cell, $value)
{ {
if (is_object($value)) {
return $this->bindObjectValue($cell, $value);
}
// sanitize UTF-8 strings // sanitize UTF-8 strings
if (is_string($value)) { if (is_string($value)) {
$value = StringHelper::sanitizeUTF8($value); $value = StringHelper::sanitizeUTF8($value);
} }
if ($value === null && $this->convertNull === false) {
$cell->setValueExplicit($value, DataType::TYPE_NULL);
} elseif (is_bool($value) && $this->convertBoolean === false) {
$cell->setValueExplicit($value, DataType::TYPE_BOOL);
} elseif ((is_int($value) || is_float($value)) && $this->convertNumeric === false) {
$cell->setValueExplicit($value, DataType::TYPE_NUMERIC);
} elseif (is_string($value) && strlen($value) > 1 && $value[0] === '=' && $this->convertFormula === false) {
$cell->setValueExplicit($value, DataType::TYPE_FORMULA);
} else {
if (is_string($value) && strlen($value) > 1 && $value[0] === '=') {
$cell->getStyle()->setQuotePrefix(true);
}
$cell->setValueExplicit((string) $value, DataType::TYPE_STRING);
}
return true;
}
protected function bindObjectValue(Cell $cell, object $value): bool
{
// Handle any objects that might be injected
if ($value instanceof DateTimeInterface) {
$value = $value->format('Y-m-d H:i:s');
} elseif ($value instanceof RichText) {
$cell->setValueExplicit($value, DataType::TYPE_INLINE);
return true;
}
$cell->setValueExplicit((string) $value, DataType::TYPE_STRING); $cell->setValueExplicit((string) $value, DataType::TYPE_STRING);
// Done!
return true; return true;
} }
} }

View File

@ -0,0 +1,103 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Helper;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Shared\Drawing;
use PhpOffice\PhpSpreadsheet\Style\Font;
class Dimension
{
public const UOM_CENTIMETERS = 'cm';
public const UOM_MILLIMETERS = 'mm';
public const UOM_INCHES = 'in';
public const UOM_PIXELS = 'px';
public const UOM_POINTS = 'pt';
public const UOM_PICA = 'pc';
/**
* Based on 96 dpi.
*/
const ABSOLUTE_UNITS = [
self::UOM_CENTIMETERS => 96.0 / 2.54,
self::UOM_MILLIMETERS => 96.0 / 25.4,
self::UOM_INCHES => 96.0,
self::UOM_PIXELS => 1.0,
self::UOM_POINTS => 96.0 / 72,
self::UOM_PICA => 96.0 * 12 / 72,
];
/**
* Based on a standard column width of 8.54 units in MS Excel.
*/
const RELATIVE_UNITS = [
'em' => 10.0 / 8.54,
'ex' => 10.0 / 8.54,
'ch' => 10.0 / 8.54,
'rem' => 10.0 / 8.54,
'vw' => 8.54,
'vh' => 8.54,
'vmin' => 8.54,
'vmax' => 8.54,
'%' => 8.54 / 100,
];
/**
* @var float|int If this is a width, then size is measured in pixels (if is set)
* or in Excel's default column width units if $unit is null.
* If this is a height, then size is measured in pixels ()
* or in points () if $unit is null.
*/
protected $size;
/**
* @var null|string
*/
protected $unit;
public function __construct(string $dimension)
{
[$size, $unit] = sscanf($dimension, '%[1234567890.]%s');
$unit = strtolower(trim($unit));
// If a UoM is specified, then convert the size to pixels for internal storage
if (isset(self::ABSOLUTE_UNITS[$unit])) {
$size *= self::ABSOLUTE_UNITS[$unit];
$this->unit = self::UOM_PIXELS;
} elseif (isset(self::RELATIVE_UNITS[$unit])) {
$size *= self::RELATIVE_UNITS[$unit];
$size = round($size, 4);
}
$this->size = $size;
}
public function width(): float
{
return (float) ($this->unit === null)
? $this->size
: round(Drawing::pixelsToCellDimension((int) $this->size, new Font(false)), 4);
}
public function height(): float
{
return (float) ($this->unit === null)
? $this->size
: $this->toUnit(self::UOM_POINTS);
}
public function toUnit(string $unitOfMeasure): float
{
$unitOfMeasure = strtolower($unitOfMeasure);
if (!array_key_exists($unitOfMeasure, self::ABSOLUTE_UNITS)) {
throw new Exception("{$unitOfMeasure} is not a vaid unit of measure");
}
$size = $this->size;
if ($this->unit === null) {
$size = Drawing::cellDimensionToPixels($size, new Font(false));
}
return $size / self::ABSOLUTE_UNITS[$unitOfMeasure];
}
}

View File

@ -75,15 +75,15 @@ abstract class IOFactory
/** /**
* Loads Spreadsheet from file using automatic Reader\IReader resolution. * Loads Spreadsheet from file using automatic Reader\IReader resolution.
* *
* @param string $pFilename The name of the spreadsheet file * @param string $filename The name of the spreadsheet file
* *
* @return Spreadsheet * @return Spreadsheet
*/ */
public static function load($pFilename) public static function load(string $filename, int $flags = 0)
{ {
$reader = self::createReaderForFile($pFilename); $reader = self::createReaderForFile($filename);
return $reader->load($pFilename); return $reader->load($filename, $flags);
} }
/** /**

View File

@ -137,6 +137,13 @@ abstract class BaseReader implements IReader
return $this->securityScanner; return $this->securityScanner;
} }
protected function processFlags(int $flags): void
{
if (((bool) ($flags & self::LOAD_WITH_CHARTS)) === true) {
$this->setIncludeCharts(true);
}
}
/** /**
* Open file for reading. * Open file for reading.
* *

View File

@ -236,12 +236,12 @@ class Csv extends BaseReader
/** /**
* Loads Spreadsheet from file. * Loads Spreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Create new Spreadsheet // Create new Spreadsheet
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();

View File

@ -235,12 +235,12 @@ class Gnumeric extends BaseReader
/** /**
* Loads Spreadsheet from file. * Loads Spreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Create new Spreadsheet // Create new Spreadsheet
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$spreadsheet->removeSheetByIndex(0); $spreadsheet->removeSheetByIndex(0);

View File

@ -7,6 +7,7 @@ use DOMElement;
use DOMNode; use DOMNode;
use DOMText; use DOMText;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Helper\Dimension as CssDimension;
use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner; use PhpOffice\PhpSpreadsheet\Reader\Security\XmlScanner;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border; use PhpOffice\PhpSpreadsheet\Style\Border;
@ -204,12 +205,12 @@ class Html extends BaseReader
/** /**
* Loads Spreadsheet from file. * Loads Spreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Create new Spreadsheet // Create new Spreadsheet
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
@ -527,14 +528,14 @@ class Html extends BaseReader
private function processDomElementWidth(Worksheet $sheet, string $column, array $attributeArray): void private function processDomElementWidth(Worksheet $sheet, string $column, array $attributeArray): void
{ {
if (isset($attributeArray['width'])) { if (isset($attributeArray['width'])) {
$sheet->getColumnDimension($column)->setWidth($attributeArray['width']); $sheet->getColumnDimension($column)->setWidth((new CssDimension($attributeArray['width']))->width());
} }
} }
private function processDomElementHeight(Worksheet $sheet, int $row, array $attributeArray): void private function processDomElementHeight(Worksheet $sheet, int $row, array $attributeArray): void
{ {
if (isset($attributeArray['height'])) { if (isset($attributeArray['height'])) {
$sheet->getRowDimension($row)->setRowHeight($attributeArray['height']); $sheet->getRowDimension($row)->setRowHeight((new CssDimension($attributeArray['height']))->height());
} }
} }
@ -878,14 +879,14 @@ class Html extends BaseReader
case 'width': case 'width':
$sheet->getColumnDimension($column)->setWidth( $sheet->getColumnDimension($column)->setWidth(
(float) str_replace(['px', 'pt'], '', $styleValue) (new CssDimension($styleValue ?? ''))->width()
); );
break; break;
case 'height': case 'height':
$sheet->getRowDimension($row)->setRowHeight( $sheet->getRowDimension($row)->setRowHeight(
(float) str_replace(['px', 'pt'], '', $styleValue) (new CssDimension($styleValue ?? ''))->height()
); );
break; break;
@ -914,7 +915,7 @@ class Html extends BaseReader
*/ */
public function getStyleColor($value) public function getStyleColor($value)
{ {
if (strpos($value, '#') === 0) { if (strpos($value ?? '', '#') === 0) {
return substr($value, 1); return substr($value, 1);
} }

View File

@ -4,6 +4,8 @@ namespace PhpOffice\PhpSpreadsheet\Reader;
interface IReader interface IReader
{ {
public const LOAD_WITH_CHARTS = 1;
/** /**
* IReader constructor. * IReader constructor.
*/ */
@ -125,9 +127,7 @@ interface IReader
/** /**
* Loads PhpSpreadsheet from file. * Loads PhpSpreadsheet from file.
* *
* @param string $pFilename
*
* @return \PhpOffice\PhpSpreadsheet\Spreadsheet * @return \PhpOffice\PhpSpreadsheet\Spreadsheet
*/ */
public function load($pFilename); public function load(string $pFilename, int $flags = 0);
} }

View File

@ -231,12 +231,12 @@ class Ods extends BaseReader
/** /**
* Loads PhpSpreadsheet from file. * Loads PhpSpreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Create new Spreadsheet // Create new Spreadsheet
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();

View File

@ -197,12 +197,12 @@ class Slk extends BaseReader
/** /**
* Loads PhpSpreadsheet from file. * Loads PhpSpreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Create new Spreadsheet // Create new Spreadsheet
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();

View File

@ -17,6 +17,7 @@ use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Shared\OLE; use PhpOffice\PhpSpreadsheet\Shared\OLE;
use PhpOffice\PhpSpreadsheet\Shared\OLERead; use PhpOffice\PhpSpreadsheet\Shared\OLERead;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Shared\Xls as SharedXls;
use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment; use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Borders; use PhpOffice\PhpSpreadsheet\Style\Borders;
@ -622,12 +623,12 @@ class Xls extends BaseReader
/** /**
* Loads PhpSpreadsheet from file. * Loads PhpSpreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Read the OLE file // Read the OLE file
$this->loadOLE($pFilename); $this->loadOLE($pFilename);
@ -1102,12 +1103,12 @@ class Xls extends BaseReader
$endOffsetX = $spContainer->getEndOffsetX(); $endOffsetX = $spContainer->getEndOffsetX();
$endOffsetY = $spContainer->getEndOffsetY(); $endOffsetY = $spContainer->getEndOffsetY();
$width = \PhpOffice\PhpSpreadsheet\Shared\Xls::getDistanceX($this->phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX); $width = SharedXls::getDistanceX($this->phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX);
$height = \PhpOffice\PhpSpreadsheet\Shared\Xls::getDistanceY($this->phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY); $height = SharedXls::getDistanceY($this->phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);
// calculate offsetX and offsetY of the shape // calculate offsetX and offsetY of the shape
$offsetX = $startOffsetX * \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeCol($this->phpSheet, $startColumn) / 1024; $offsetX = $startOffsetX * SharedXls::sizeCol($this->phpSheet, $startColumn) / 1024;
$offsetY = $startOffsetY * \PhpOffice\PhpSpreadsheet\Shared\Xls::sizeRow($this->phpSheet, $startRow) / 256; $offsetY = $startOffsetY * SharedXls::sizeRow($this->phpSheet, $startRow) / 256;
switch ($obj['otObjType']) { switch ($obj['otObjType']) {
case 0x19: case 0x19:
@ -1143,6 +1144,7 @@ class Xls extends BaseReader
// need check because some blip types are not supported by Escher reader such as EMF // need check because some blip types are not supported by Escher reader such as EMF
if ($blip = $BSE->getBlip()) { if ($blip = $BSE->getBlip()) {
$ih = imagecreatefromstring($blip->getData()); $ih = imagecreatefromstring($blip->getData());
if ($ih !== false) {
$drawing = new MemoryDrawing(); $drawing = new MemoryDrawing();
$drawing->setImageResource($ih); $drawing->setImageResource($ih);
@ -1160,6 +1162,8 @@ class Xls extends BaseReader
break; break;
case BSE::BLIPTYPE_PNG: case BSE::BLIPTYPE_PNG:
imagealphablending($ih, false);
imagesavealpha($ih, true);
$drawing->setRenderingFunction(MemoryDrawing::RENDERING_PNG); $drawing->setRenderingFunction(MemoryDrawing::RENDERING_PNG);
$drawing->setMimeType(MemoryDrawing::MIMETYPE_PNG); $drawing->setMimeType(MemoryDrawing::MIMETYPE_PNG);
@ -1170,6 +1174,7 @@ class Xls extends BaseReader
$drawing->setCoordinates($spContainer->getStartCoordinates()); $drawing->setCoordinates($spContainer->getStartCoordinates());
} }
} }
}
break; break;
default: default:

View File

@ -5,62 +5,62 @@ namespace PhpOffice\PhpSpreadsheet\Reader\Xls\Color;
class BIFF8 class BIFF8
{ {
protected static $map = [ protected static $map = [
'000000' => 0x08, 0x08 => '000000',
'FFFFFF' => 0x09, 0x09 => 'FFFFFF',
'FF0000' => 0x0A, 0x0A => 'FF0000',
'00FF00' => 0x0B, 0x0B => '00FF00',
'0000FF' => 0x0C, 0x0C => '0000FF',
'FFFF00' => 0x0D, 0x0D => 'FFFF00',
'FF00FF' => 0x0E, 0x0E => 'FF00FF',
'00FFFF' => 0x0F, 0x0F => '00FFFF',
'800000' => 0x10, 0x10 => '800000',
'008000' => 0x11, 0x11 => '008000',
'000080' => 0x12, 0x12 => '000080',
'808000' => 0x13, 0x13 => '808000',
'800080' => 0x14, 0x14 => '800080',
'008080' => 0x15, 0x15 => '008080',
'C0C0C0' => 0x16, 0x16 => 'C0C0C0',
'808080' => 0x17, 0x17 => '808080',
'9999FF' => 0x18, 0x18 => '9999FF',
'993366' => 0x19, 0x19 => '993366',
'FFFFCC' => 0x1A, 0x1A => 'FFFFCC',
'CCFFFF' => 0x1B, 0x1B => 'CCFFFF',
'660066' => 0x1C, 0x1C => '660066',
'FF8080' => 0x1D, 0x1D => 'FF8080',
'0066CC' => 0x1E, 0x1E => '0066CC',
'CCCCFF' => 0x1F, 0x1F => 'CCCCFF',
// '000080' => 0x20, 0x20 => '000080',
// 'FF00FF' => 0x21, 0x21 => 'FF00FF',
// 'FFFF00' => 0x22, 0x22 => 'FFFF00',
// '00FFFF' => 0x23, 0x23 => '00FFFF',
// '800080' => 0x24, 0x24 => '800080',
// '800000' => 0x25, 0x25 => '800000',
// '008080' => 0x26, 0x26 => '008080',
// '0000FF' => 0x27, 0x27 => '0000FF',
'00CCFF' => 0x28, 0x28 => '00CCFF',
// 'CCFFFF' => 0x29, 0x29 => 'CCFFFF',
'CCFFCC' => 0x2A, 0x2A => 'CCFFCC',
'FFFF99' => 0x2B, 0x2B => 'FFFF99',
'99CCFF' => 0x2C, 0x2C => '99CCFF',
'FF99CC' => 0x2D, 0x2D => 'FF99CC',
'CC99FF' => 0x2E, 0x2E => 'CC99FF',
'FFCC99' => 0x2F, 0x2F => 'FFCC99',
'3366FF' => 0x30, 0x30 => '3366FF',
'33CCCC' => 0x31, 0x31 => '33CCCC',
'99CC00' => 0x32, 0x32 => '99CC00',
'FFCC00' => 0x33, 0x33 => 'FFCC00',
'FF9900' => 0x34, 0x34 => 'FF9900',
'FF6600' => 0x35, 0x35 => 'FF6600',
'666699' => 0x36, 0x36 => '666699',
'969696' => 0x37, 0x37 => '969696',
'003366' => 0x38, 0x38 => '003366',
'339966' => 0x39, 0x39 => '339966',
'003300' => 0x3A, 0x3A => '003300',
'333300' => 0x3B, 0x3B => '333300',
'993300' => 0x3C, 0x3C => '993300',
// '993366' => 0x3D, 0x3D => '993366',
'333399' => 0x3E, 0x3E => '333399',
'333333' => 0x3F, 0x3F => '333333',
]; ];
/** /**

View File

@ -310,13 +310,12 @@ class Xlsx extends BaseReader
/** /**
* Loads Spreadsheet from file. * Loads Spreadsheet from file.
* *
* @param string $pFilename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($pFilename) public function load(string $pFilename, int $flags = 0)
{ {
File::assertFile($pFilename); File::assertFile($pFilename);
$this->processFlags($flags);
// Initialisations // Initialisations
$excel = new Spreadsheet(); $excel = new Spreadsheet();

View File

@ -236,18 +236,18 @@ class Xml extends BaseReader
/** /**
* Loads Spreadsheet from file. * Loads Spreadsheet from file.
* *
* @param string $filename
*
* @return Spreadsheet * @return Spreadsheet
*/ */
public function load($filename) public function load(string $pFilename, int $flags = 0)
{ {
$this->processFlags($flags);
// Create new Spreadsheet // Create new Spreadsheet
$spreadsheet = new Spreadsheet(); $spreadsheet = new Spreadsheet();
$spreadsheet->removeSheetByIndex(0); $spreadsheet->removeSheetByIndex(0);
// Load into this instance // Load into this instance
return $this->loadIntoExisting($filename, $spreadsheet); return $this->loadIntoExisting($pFilename, $spreadsheet);
} }
/** /**

View File

@ -115,7 +115,7 @@ class PageSettings
private function setLayout(stdClass $printDefaults, SimpleXMLElement $pageSetupAttributes): void private function setLayout(stdClass $printDefaults, SimpleXMLElement $pageSetupAttributes): void
{ {
$printDefaults->orientation = (string) strtolower($pageSetupAttributes->Orientation) ?: PageSetup::ORIENTATION_PORTRAIT; $printDefaults->orientation = (string) strtolower($pageSetupAttributes->Orientation ?? '') ?: PageSetup::ORIENTATION_PORTRAIT;
$printDefaults->horizontalCentered = (bool) $pageSetupAttributes->CenterHorizontal ?: false; $printDefaults->horizontalCentered = (bool) $pageSetupAttributes->CenterHorizontal ?: false;
$printDefaults->verticalCentered = (bool) $pageSetupAttributes->CenterVertical ?: false; $printDefaults->verticalCentered = (bool) $pageSetupAttributes->CenterVertical ?: false;
} }

View File

@ -9,26 +9,26 @@ class Drawing
/** /**
* Convert pixels to EMU. * Convert pixels to EMU.
* *
* @param int $pValue Value in pixels * @param int $pixelValue Value in pixels
* *
* @return int Value in EMU * @return int Value in EMU
*/ */
public static function pixelsToEMU($pValue) public static function pixelsToEMU($pixelValue)
{ {
return $pValue * 9525; return $pixelValue * 9525;
} }
/** /**
* Convert EMU to pixels. * Convert EMU to pixels.
* *
* @param int $pValue Value in EMU * @param int $emuValue Value in EMU
* *
* @return int Value in pixels * @return int Value in pixels
*/ */
public static function EMUToPixels($pValue) public static function EMUToPixels($emuValue)
{ {
if ($pValue != 0) { if ($emuValue != 0) {
return (int) round($pValue / 9525); return (int) round($emuValue / 9525);
} }
return 0; return 0;
@ -39,12 +39,12 @@ class Drawing
* By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875 * By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
* This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional. * This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
* *
* @param int $pValue Value in pixels * @param int $pixelValue Value in pixels
* @param \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont Default font of the workbook * @param \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont Default font of the workbook
* *
* @return int Value in cell dimension * @return float|int Value in cell dimension
*/ */
public static function pixelsToCellDimension($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont) public static function pixelsToCellDimension($pixelValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
{ {
// Font name and size // Font name and size
$name = $pDefaultFont->getName(); $name = $pDefaultFont->getName();
@ -52,25 +52,25 @@ class Drawing
if (isset(Font::$defaultColumnWidths[$name][$size])) { if (isset(Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined // Exact width can be determined
$colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['width'] / Font::$defaultColumnWidths[$name][$size]['px']; return $pixelValue * Font::$defaultColumnWidths[$name][$size]['width']
} else { / Font::$defaultColumnWidths[$name][$size]['px'];
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width'] / Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
} }
return $colWidth; // We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
return $pixelValue * 11 * Font::$defaultColumnWidths['Calibri'][11]['width']
/ Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
} }
/** /**
* Convert column width from (intrinsic) Excel units to pixels. * Convert column width from (intrinsic) Excel units to pixels.
* *
* @param float $pValue Value in cell dimension * @param float $cellWidth Value in cell dimension
* @param \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont Default font of the workbook * @param \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont Default font of the workbook
* *
* @return int Value in pixels * @return int Value in pixels
*/ */
public static function cellDimensionToPixels($pValue, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont) public static function cellDimensionToPixels($cellWidth, \PhpOffice\PhpSpreadsheet\Style\Font $pDefaultFont)
{ {
// Font name and size // Font name and size
$name = $pDefaultFont->getName(); $name = $pDefaultFont->getName();
@ -78,11 +78,13 @@ class Drawing
if (isset(Font::$defaultColumnWidths[$name][$size])) { if (isset(Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined // Exact width can be determined
$colWidth = $pValue * Font::$defaultColumnWidths[$name][$size]['px'] / Font::$defaultColumnWidths[$name][$size]['width']; $colWidth = $cellWidth * Font::$defaultColumnWidths[$name][$size]['px']
/ Font::$defaultColumnWidths[$name][$size]['width'];
} else { } else {
// We don't have data for this particular font and size, use approximation by // We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11 // extrapolating from Calibri 11
$colWidth = $pValue * $size * Font::$defaultColumnWidths['Calibri'][11]['px'] / Font::$defaultColumnWidths['Calibri'][11]['width'] / 11; $colWidth = $cellWidth * $size * Font::$defaultColumnWidths['Calibri'][11]['px']
/ Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
} }
// Round pixels to closest integer // Round pixels to closest integer
@ -94,26 +96,26 @@ class Drawing
/** /**
* Convert pixels to points. * Convert pixels to points.
* *
* @param int $pValue Value in pixels * @param int $pixelValue Value in pixels
* *
* @return float Value in points * @return float Value in points
*/ */
public static function pixelsToPoints($pValue) public static function pixelsToPoints($pixelValue)
{ {
return $pValue * 0.75; return $pixelValue * 0.75;
} }
/** /**
* Convert points to pixels. * Convert points to pixels.
* *
* @param int $pValue Value in points * @param int $pointValue Value in points
* *
* @return int Value in pixels * @return int Value in pixels
*/ */
public static function pointsToPixels($pValue) public static function pointsToPixels($pointValue)
{ {
if ($pValue != 0) { if ($pointValue != 0) {
return (int) ceil($pValue / 0.75); return (int) ceil($pointValue / 0.75);
} }
return 0; return 0;

View File

@ -265,7 +265,7 @@ class Font
} }
// Convert from pixel width to column width // Convert from pixel width to column width
$columnWidth = Drawing::pixelsToCellDimension($columnWidth, $defaultFont); $columnWidth = Drawing::pixelsToCellDimension((int) $columnWidth, $defaultFont);
// Return // Return
return (int) round($columnWidth, 6); return (int) round($columnWidth, 6);

View File

@ -502,7 +502,7 @@ class StringHelper
*/ */
public static function strToLower($pValue) public static function strToLower($pValue)
{ {
return mb_convert_case($pValue, MB_CASE_LOWER, 'UTF-8'); return mb_convert_case($pValue ?? '', MB_CASE_LOWER, 'UTF-8');
} }
/** /**

View File

@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Shared; namespace PhpOffice\PhpSpreadsheet\Shared;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate; use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Helper\Dimension;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class Xls class Xls
@ -76,12 +77,11 @@ class Xls
} elseif ($sheet->getDefaultRowDimension()->getRowHeight() != -1) { } elseif ($sheet->getDefaultRowDimension()->getRowHeight() != -1) {
// then we have a default row dimension with explicit height // then we have a default row dimension with explicit height
$defaultRowDimension = $sheet->getDefaultRowDimension(); $defaultRowDimension = $sheet->getDefaultRowDimension();
$rowHeight = $defaultRowDimension->getRowHeight(); $pixelRowHeight = $defaultRowDimension->getRowHeight(Dimension::UOM_PIXELS);
$pixelRowHeight = Drawing::pointsToPixels($rowHeight);
} else { } else {
// we don't even have any default row dimension. Height depends on default font // we don't even have any default row dimension. Height depends on default font
$pointRowHeight = Font::getDefaultRowHeightByFont($font); $pointRowHeight = Font::getDefaultRowHeightByFont($font);
$pixelRowHeight = Font::fontSizeToPixels($pointRowHeight); $pixelRowHeight = Font::fontSizeToPixels((int) $pointRowHeight);
} }
// now find the effective row height in pixels // now find the effective row height in pixels
@ -91,7 +91,7 @@ class Xls
$effectivePixelRowHeight = $pixelRowHeight; $effectivePixelRowHeight = $pixelRowHeight;
} }
return $effectivePixelRowHeight; return (int) $effectivePixelRowHeight;
} }
/** /**

View File

@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Helper\Dimension as CssDimension;
class ColumnDimension extends Dimension class ColumnDimension extends Dimension
{ {
/** /**
@ -63,20 +65,32 @@ class ColumnDimension extends Dimension
/** /**
* Get Width. * Get Width.
*
* Each unit of column width is equal to the width of one character in the default font size.
* By default, this will be the return value; but this method also accepts a unit of measure argument and will
* return the value converted to the specified UoM using an approximation method.
*/ */
public function getWidth(): float public function getWidth(?string $unitOfMeasure = null): float
{ {
return $this->width; return ($unitOfMeasure === null || $this->width < 0)
? $this->width
: (new CssDimension((string) $this->width))->toUnit($unitOfMeasure);
} }
/** /**
* Set Width. * Set Width.
* *
* Each unit of column width is equal to the width of one character in the default font size.
* By default, this will be the unit of measure for the passed value; but this method accepts a unit of measure
* argument, and will convert the value from the specified UoM using an approximation method.
*
* @return $this * @return $this
*/ */
public function setWidth(float $width) public function setWidth(float $width, ?string $unitOfMeasure = null)
{ {
$this->width = $width; $this->width = ($unitOfMeasure === null || $width < 0)
? $width
: (new CssDimension("{$width}{$unitOfMeasure}"))->width();
return $this; return $this;
} }

View File

@ -2,6 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Worksheet; namespace PhpOffice\PhpSpreadsheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Helper\Dimension as CssDimension;
class RowDimension extends Dimension class RowDimension extends Dimension
{ {
/** /**
@ -63,24 +65,32 @@ class RowDimension extends Dimension
/** /**
* Get Row Height. * Get Row Height.
* By default, this will be in points; but this method accepts a unit of measure
* argument, and will convert the value to the specified UoM.
* *
* @return float * @return float
*/ */
public function getRowHeight() public function getRowHeight(?string $unitOfMeasure = null)
{ {
return $this->height; return ($unitOfMeasure === null || $this->height < 0)
? $this->height
: (new CssDimension($this->height . CssDimension::UOM_POINTS))->toUnit($unitOfMeasure);
} }
/** /**
* Set Row Height. * Set Row Height.
* *
* @param float $height * @param float $height in points
* By default, this will be the passed argument value; but this method accepts a unit of measure
* argument, and will convert the passed argument value to points from the specified UoM
* *
* @return $this * @return $this
*/ */
public function setRowHeight($height) public function setRowHeight($height, ?string $unitOfMeasure = null)
{ {
$this->height = $height; $this->height = ($unitOfMeasure === null || $height < 0)
? $height
: (new CssDimension("{$height}{$unitOfMeasure}"))->height();
return $this; return $this;
} }

View File

@ -6,7 +6,7 @@ abstract class BaseWriter implements IWriter
{ {
/** /**
* Write charts that are defined in the workbook? * Write charts that are defined in the workbook?
* Identifies whether the Writer should write definitions for any charts that exist in the PhpSpreadsheet object;. * Identifies whether the Writer should write definitions for any charts that exist in the PhpSpreadsheet object.
* *
* @var bool * @var bool
*/ */
@ -94,6 +94,13 @@ abstract class BaseWriter implements IWriter
return $this->diskCachingDirectory; return $this->diskCachingDirectory;
} }
protected function processFlags(int $flags): void
{
if (((bool) ($flags & self::SAVE_WITH_CHARTS)) === true) {
$this->setIncludeCharts(true);
}
}
/** /**
* Open file handle. * Open file handle.
* *

View File

@ -86,8 +86,10 @@ class Csv extends BaseWriter
* *
* @param resource|string $pFilename * @param resource|string $pFilename
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$this->processFlags($flags);
// Fetch sheet // Fetch sheet
$sheet = $this->spreadsheet->getSheet($this->sheetIndex); $sheet = $this->spreadsheet->getSheet($this->sheetIndex);

View File

@ -153,8 +153,10 @@ class Html extends BaseWriter
* *
* @param resource|string $pFilename * @param resource|string $pFilename
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$this->processFlags($flags);
// Open file // Open file
$this->openFileHandle($pFilename); $this->openFileHandle($pFilename);

View File

@ -6,6 +6,8 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
interface IWriter interface IWriter
{ {
public const SAVE_WITH_CHARTS = 1;
/** /**
* IWriter constructor. * IWriter constructor.
*/ */
@ -59,7 +61,7 @@ interface IWriter
* *
* @param resource|string $pFilename Name of the file to save * @param resource|string $pFilename Name of the file to save
*/ */
public function save($pFilename); public function save($pFilename, int $flags = 0): void;
/** /**
* Get use disk caching where possible? * Get use disk caching where possible?

View File

@ -115,12 +115,14 @@ class Ods extends BaseWriter
* *
* @param resource|string $pFilename * @param resource|string $pFilename
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
if (!$this->spreadSheet) { if (!$this->spreadSheet) {
throw new WriterException('PhpSpreadsheet object unassigned.'); throw new WriterException('PhpSpreadsheet object unassigned.');
} }
$this->processFlags($flags);
// garbage collect // garbage collect
$this->spreadSheet->garbageCollect(); $this->spreadSheet->garbageCollect();

View File

@ -22,7 +22,7 @@ class Dompdf extends Pdf
* *
* @param string $pFilename Name of the file to save as * @param string $pFilename Name of the file to save as
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$fileHandle = parent::prepareForSave($pFilename); $fileHandle = parent::prepareForSave($pFilename);

View File

@ -24,7 +24,7 @@ class Mpdf extends Pdf
* *
* @param string $pFilename Name of the file to save as * @param string $pFilename Name of the file to save as
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$fileHandle = parent::prepareForSave($pFilename); $fileHandle = parent::prepareForSave($pFilename);

View File

@ -38,7 +38,7 @@ class Tcpdf extends Pdf
* *
* @param string $pFilename Name of the file to save as * @param string $pFilename Name of the file to save as
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$fileHandle = parent::prepareForSave($pFilename); $fileHandle = parent::prepareForSave($pFilename);

View File

@ -119,8 +119,10 @@ class Xls extends BaseWriter
* *
* @param resource|string $pFilename * @param resource|string $pFilename
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$this->processFlags($flags);
// garbage collect // garbage collect
$this->spreadsheet->garbageCollect(); $this->spreadsheet->garbageCollect();

View File

@ -286,8 +286,10 @@ class Xlsx extends BaseWriter
* *
* @param resource|string $pFilename * @param resource|string $pFilename
*/ */
public function save($pFilename): void public function save($pFilename, int $flags = 0): void
{ {
$this->processFlags($flags);
// garbage collect // garbage collect
$this->pathNames = []; $this->pathNames = [];
$this->spreadSheet->garbageCollect(); $this->spreadSheet->garbageCollect();

View File

@ -1256,7 +1256,7 @@ class Worksheet extends WriterPart
$objWriter, $objWriter,
$this->getParentWriter()->getOffice2003Compatibility() === false, $this->getParentWriter()->getOffice2003Compatibility() === false,
'v', 'v',
($this->getParentWriter()->getPreCalculateFormulas() && !is_array($calculatedValue) && substr($calculatedValue, 0, 1) !== '#') ($this->getParentWriter()->getPreCalculateFormulas() && !is_array($calculatedValue) && substr($calculatedValue ?? '', 0, 1) !== '#')
? StringHelper::formatNumber($calculatedValue) : '0' ? StringHelper::formatNumber($calculatedValue) : '0'
); );
} }

View File

@ -341,7 +341,7 @@ class FunctionsTest extends TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$remoteCell->method('isFormula') $remoteCell->method('isFormula')
->willReturn(substr($value, 0, 1) == '='); ->willReturn(substr($value ?? '', 0, 1) == '=');
$remoteSheet = $this->getMockBuilder(Worksheet::class) $remoteSheet = $this->getMockBuilder(Worksheet::class)
->disableOriginalConstructor() ->disableOriginalConstructor()

View File

@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Collection\Cells;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat; use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class AdvancedValueBinderTest extends TestCase class AdvancedValueBinderTest extends TestCase
@ -42,6 +43,23 @@ class AdvancedValueBinderTest extends TestCase
StringHelper::setThousandsSeparator($this->thousandsSeparator); StringHelper::setThousandsSeparator($this->thousandsSeparator);
} }
public function testNullValue(): void
{
/** @var Cell&MockObject $cellStub */
$cellStub = $this->getMockBuilder(Cell::class)
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$cellStub->expects(self::once())
->method('setValueExplicit')
->with(null, DataType::TYPE_NULL)
->willReturn(true);
$binder = new AdvancedValueBinder();
$binder->bindValue($cellStub, null);
}
/** /**
* @dataProvider currencyProvider * @dataProvider currencyProvider
* *
@ -105,6 +123,7 @@ class AdvancedValueBinderTest extends TestCase
['€2.020,20', 2020.2, $currencyEURO, '.', ',', '€'], ['€2.020,20', 2020.2, $currencyEURO, '.', ',', '€'],
['€ 2.020,20', 2020.2, $currencyEURO, '.', ',', '€'], ['€ 2.020,20', 2020.2, $currencyEURO, '.', ',', '€'],
['€2,020.22', 2020.22, $currencyEURO, ',', '.', '€'], ['€2,020.22', 2020.22, $currencyEURO, ',', '.', '€'],
['$10.11', 10.11, $currencyUSD, ',', '.', '€'],
]; ];
} }

View File

@ -0,0 +1,261 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Cell;
use DateTime;
use DateTimeZone;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Cell\StringValueBinder;
use PhpOffice\PhpSpreadsheet\RichText\RichText;
use PhpOffice\PhpSpreadsheet\Style\Style;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
class StringValueBinderTest extends TestCase
{
/**
* @param mixed $expectedValue
*
* @return Cell&MockObject
*/
protected function createCellStub($expectedValue, string $expectedDataType, bool $quotePrefix = false): MockObject
{
/** @var Style&MockObject $styleStub */
$styleStub = $this->getMockBuilder(Style::class)
->disableOriginalConstructor()
->getMock();
/** @var Cell&MockObject $cellStub */
$cellStub = $this->getMockBuilder(Cell::class)
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$cellStub->expects(self::once())
->method('setValueExplicit')
->with($expectedValue, $expectedDataType)
->willReturn(true);
$cellStub->expects($quotePrefix ? self::once() : self::never())
->method('getStyle')
->willReturn($styleStub);
return $cellStub;
}
/**
* @dataProvider providerDataValuesDefault
*
* @param mixed $value
* @param mixed $expectedValue
*/
public function testStringValueBinderDefaultBehaviour(
$value,
$expectedValue,
string $expectedDataType,
bool $quotePrefix = false
): void {
$cellStub = $this->createCellStub($expectedValue, $expectedDataType, $quotePrefix);
$binder = new StringValueBinder();
$binder->bindValue($cellStub, $value);
}
public function providerDataValuesDefault(): array
{
return [
[null, '', DataType::TYPE_STRING],
[true, '1', DataType::TYPE_STRING],
[false, '', DataType::TYPE_STRING],
['', '', DataType::TYPE_STRING],
['123', '123', DataType::TYPE_STRING],
['123.456', '123.456', DataType::TYPE_STRING],
['0.123', '0.123', DataType::TYPE_STRING],
['.123', '.123', DataType::TYPE_STRING],
['-0.123', '-0.123', DataType::TYPE_STRING],
['-.123', '-.123', DataType::TYPE_STRING],
['1.23e-4', '1.23e-4', DataType::TYPE_STRING],
['ABC', 'ABC', DataType::TYPE_STRING],
['=SUM(A1:C3)', '=SUM(A1:C3)', DataType::TYPE_STRING, true],
[123, '123', DataType::TYPE_STRING],
[123.456, '123.456', DataType::TYPE_STRING],
[0.123, '0.123', DataType::TYPE_STRING],
[.123, '0.123', DataType::TYPE_STRING],
[-0.123, '-0.123', DataType::TYPE_STRING],
[-.123, '-0.123', DataType::TYPE_STRING],
[1.23e-4, '0.000123', DataType::TYPE_STRING],
[1.23e-24, '1.23E-24', DataType::TYPE_STRING],
[new DateTime('2021-06-01 00:00:00', new DateTimeZone('UTC')), '2021-06-01 00:00:00', DataType::TYPE_STRING],
];
}
/**
* @dataProvider providerDataValuesSuppressNullConversion
*
* @param mixed $value
* @param mixed $expectedValue
*/
public function testStringValueBinderSuppressNullConversion(
$value,
$expectedValue,
string $expectedDataType,
bool $quotePrefix = false
): void {
$cellStub = $this->createCellStub($expectedValue, $expectedDataType, $quotePrefix);
$binder = new StringValueBinder();
$binder->setNullConversion(false);
$binder->bindValue($cellStub, $value);
}
public function providerDataValuesSuppressNullConversion(): array
{
return [
[null, null, DataType::TYPE_NULL],
];
}
/**
* @dataProvider providerDataValuesSuppressBooleanConversion
*
* @param mixed $value
* @param mixed $expectedValue
*/
public function testStringValueBinderSuppressBooleanConversion(
$value,
$expectedValue,
string $expectedDataType,
bool $quotePrefix = false
): void {
$cellStub = $this->createCellStub($expectedValue, $expectedDataType, $quotePrefix);
$binder = new StringValueBinder();
$binder->setBooleanConversion(false);
$binder->bindValue($cellStub, $value);
}
public function providerDataValuesSuppressBooleanConversion(): array
{
return [
[true, true, DataType::TYPE_BOOL],
[false, false, DataType::TYPE_BOOL],
];
}
/**
* @dataProvider providerDataValuesSuppressNumericConversion
*
* @param mixed $value
* @param mixed $expectedValue
*/
public function testStringValueBinderSuppressNumericConversion(
$value,
$expectedValue,
string $expectedDataType,
bool $quotePrefix = false
): void {
$cellStub = $this->createCellStub($expectedValue, $expectedDataType, $quotePrefix);
$binder = new StringValueBinder();
$binder->setNumericConversion(false);
$binder->bindValue($cellStub, $value);
}
public function providerDataValuesSuppressNumericConversion(): array
{
return [
[123, 123, DataType::TYPE_NUMERIC],
[123.456, 123.456, DataType::TYPE_NUMERIC],
[0.123, 0.123, DataType::TYPE_NUMERIC],
[.123, 0.123, DataType::TYPE_NUMERIC],
[-0.123, -0.123, DataType::TYPE_NUMERIC],
[-.123, -0.123, DataType::TYPE_NUMERIC],
[1.23e-4, 0.000123, DataType::TYPE_NUMERIC],
[1.23e-24, 1.23E-24, DataType::TYPE_NUMERIC],
];
}
/**
* @dataProvider providerDataValuesSuppressFormulaConversion
*
* @param mixed $value
* @param mixed $expectedValue
*/
public function testStringValueBinderSuppressFormulaConversion(
$value,
$expectedValue,
string $expectedDataType,
bool $quotePrefix = false
): void {
$cellStub = $this->createCellStub($expectedValue, $expectedDataType, $quotePrefix);
$binder = new StringValueBinder();
$binder->setFormulaConversion(false);
$binder->bindValue($cellStub, $value);
}
public function providerDataValuesSuppressFormulaConversion(): array
{
return [
['=SUM(A1:C3)', '=SUM(A1:C3)', DataType::TYPE_FORMULA, false],
];
}
/**
* @dataProvider providerDataValuesSuppressAllConversion
*
* @param mixed $value
* @param mixed $expectedValue
*/
public function testStringValueBinderSuppressAllConversion(
$value,
$expectedValue,
string $expectedDataType,
bool $quotePrefix = false
): void {
$cellStub = $this->createCellStub($expectedValue, $expectedDataType, $quotePrefix);
$binder = new StringValueBinder();
$binder->setConversionForAllValueTypes(false);
$binder->bindValue($cellStub, $value);
}
public function providerDataValuesSuppressAllConversion(): array
{
return [
[null, null, DataType::TYPE_NULL],
[true, true, DataType::TYPE_BOOL],
[false, false, DataType::TYPE_BOOL],
['', '', DataType::TYPE_STRING],
['123', '123', DataType::TYPE_STRING],
['123.456', '123.456', DataType::TYPE_STRING],
['0.123', '0.123', DataType::TYPE_STRING],
['.123', '.123', DataType::TYPE_STRING],
['-0.123', '-0.123', DataType::TYPE_STRING],
['-.123', '-.123', DataType::TYPE_STRING],
['1.23e-4', '1.23e-4', DataType::TYPE_STRING],
['ABC', 'ABC', DataType::TYPE_STRING],
['=SUM(A1:C3)', '=SUM(A1:C3)', DataType::TYPE_FORMULA, false],
[123, 123, DataType::TYPE_NUMERIC],
[123.456, 123.456, DataType::TYPE_NUMERIC],
[0.123, 0.123, DataType::TYPE_NUMERIC],
[.123, 0.123, DataType::TYPE_NUMERIC],
[-0.123, -0.123, DataType::TYPE_NUMERIC],
[-.123, -0.123, DataType::TYPE_NUMERIC],
[1.23e-4, 0.000123, DataType::TYPE_NUMERIC],
[1.23e-24, 1.23E-24, DataType::TYPE_NUMERIC],
];
}
public function testStringValueBinderForRichTextObject(): void
{
$objRichText = new RichText();
$objRichText->createText('Hello World');
$cellStub = $this->createCellStub($objRichText, DataType::TYPE_INLINE);
$binder = new StringValueBinder();
$binder->setConversionForAllValueTypes(false);
$binder->bindValue($cellStub, $objRichText);
}
}

View File

@ -0,0 +1,72 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Helper;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Helper\Dimension;
use PHPUnit\Framework\TestCase;
class DimensionTest extends TestCase
{
/**
* @dataProvider providerCellWidth
*/
public function testCreateDimension(float $expectedResult, string $dimension): void
{
$result = (new Dimension($dimension))->width();
self::assertSame($expectedResult, $result);
}
/**
* @dataProvider providerConvertUoM
*/
public function testConvertDimension(float $expectedResult, string $dimension, string $unitOfMeasure): void
{
$result = (new Dimension($dimension))->toUnit($unitOfMeasure);
self::assertSame($expectedResult, $result);
}
public function testConvertDimensionInvalidUoM(): void
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('pikachu is not a vaid unit of measure');
(new Dimension('999'))->toUnit('pikachu');
}
public function providerCellWidth(): array
{
return [
[12.0, '12'],
[2.2852, '12pt'],
[4.5703, '24 pt'],
[5.1416, '36px'],
[5.7129, '2.5pc'],
[13.7109, '2.54cm'],
[13.7109, '25.4mm'],
[13.7109, '1in'],
[4.27, '50%'],
[3.7471, '3.2em'],
[2.3419, '2ch'],
[4.6838, '4ex'],
[14.0515, '12rem'],
];
}
public function providerConvertUoM(): array
{
return [
[60, '8.54', Dimension::UOM_PIXELS],
[100, '100px', Dimension::UOM_PIXELS],
[150, '200px', Dimension::UOM_POINTS],
[45, '8.54', Dimension::UOM_POINTS],
[12.5, '200px', Dimension::UOM_PICA],
[3.75, '8.54', Dimension::UOM_PICA],
[3.125, '300px', Dimension::UOM_INCHES],
[0.625, '8.54', Dimension::UOM_INCHES],
[7.9375, '300px', Dimension::UOM_CENTIMETERS],
[1.5875, '8.54', Dimension::UOM_CENTIMETERS],
[79.375, '300px', Dimension::UOM_MILLIMETERS],
[15.875, '8.54', Dimension::UOM_MILLIMETERS],
];
}
}

View File

@ -63,7 +63,7 @@ class SampleTest extends TestCase
// } // }
if (!in_array($sample, $skipped)) { if (!in_array($sample, $skipped)) {
$file = 'samples/' . $sample; $file = 'samples/' . $sample;
$result[] = [$file]; $result[$sample] = [$file];
} }
} }
} }

View File

@ -136,6 +136,7 @@ class HtmlTest extends TestCase
<tr> <tr>
<td width="50">50px</td> <td width="50">50px</td>
<td style="width: 100px;">100px</td> <td style="width: 100px;">100px</td>
<td width="50px">50px</td>
</tr> </tr>
</table>'; </table>';
$filename = HtmlHelper::createHtml($html); $filename = HtmlHelper::createHtml($html);
@ -143,10 +144,16 @@ class HtmlTest extends TestCase
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
$dimension = $firstSheet->getColumnDimension('A'); $dimension = $firstSheet->getColumnDimension('A');
self::assertNotNull($dimension);
self::assertEquals(50, $dimension->getWidth()); self::assertEquals(50, $dimension->getWidth());
$dimension = $firstSheet->getColumnDimension('B'); $dimension = $firstSheet->getColumnDimension('B');
self::assertEquals(100, $dimension->getWidth()); self::assertNotNull($dimension);
self::assertEquals(100, $dimension->getWidth('px'));
$dimension = $firstSheet->getColumnDimension('C');
self::assertNotNull($dimension);
self::assertEquals(50, $dimension->getWidth('px'));
} }
public function testCanApplyInlineHeight(): void public function testCanApplyInlineHeight(): void
@ -158,16 +165,25 @@ class HtmlTest extends TestCase
<tr> <tr>
<td style="height: 100px;">2</td> <td style="height: 100px;">2</td>
</tr> </tr>
<tr>
<td height="50px">1</td>
</tr>
</table>'; </table>';
$filename = HtmlHelper::createHtml($html); $filename = HtmlHelper::createHtml($html);
$spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true); $spreadsheet = HtmlHelper::loadHtmlIntoSpreadsheet($filename, true);
$firstSheet = $spreadsheet->getSheet(0); $firstSheet = $spreadsheet->getSheet(0);
$dimension = $firstSheet->getRowDimension(1); $dimension = $firstSheet->getRowDimension(1);
self::assertNotNull($dimension);
self::assertEquals(50, $dimension->getRowHeight()); self::assertEquals(50, $dimension->getRowHeight());
$dimension = $firstSheet->getRowDimension(2); $dimension = $firstSheet->getRowDimension(2);
self::assertEquals(100, $dimension->getRowHeight()); self::assertNotNull($dimension);
self::assertEquals(100, $dimension->getRowHeight('px'));
$dimension = $firstSheet->getRowDimension(3);
self::assertNotNull($dimension);
self::assertEquals(50, $dimension->getRowHeight('px'));
} }
public function testCanApplyAlignment(): void public function testCanApplyAlignment(): void

View File

@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader;
use PhpOffice\PhpSpreadsheet\Chart\DataSeries; use PhpOffice\PhpSpreadsheet\Chart\DataSeries;
use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SheetsXlsxChartTest extends TestCase class SheetsXlsxChartTest extends TestCase
@ -11,8 +12,8 @@ class SheetsXlsxChartTest extends TestCase
public function testLoadSheetsXlsxChart(): void public function testLoadSheetsXlsxChart(): void
{ {
$filename = 'tests/data/Reader/XLSX/sheetsChartsTest.xlsx'; $filename = 'tests/data/Reader/XLSX/sheetsChartsTest.xlsx';
$reader = IOFactory::createReader('Xlsx')->setIncludeCharts(true); $reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename); $spreadsheet = $reader->load($filename, IReader::LOAD_WITH_CHARTS);
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$charts = $worksheet->getChartCollection(); $charts = $worksheet->getChartCollection();

View File

@ -0,0 +1,42 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
class ColourTest extends AbstractFunctional
{
/**
* @var Spreadsheet
*/
private $spreadsheet;
protected function setup(): void
{
$filename = 'tests/data/Reader/XLS/Colours.xls';
$reader = new Xls();
$this->spreadsheet = $reader->load($filename);
}
public function testColours(): void
{
$colours = [];
$worksheet = $this->spreadsheet->getActiveSheet();
for ($row = 1; $row <= 7; ++$row) {
for ($column = 'A'; $column !== 'J'; ++$column) {
$cellAddress = "{$column}{$row}";
$colours[$cellAddress] = $worksheet->getStyle($cellAddress)->getFill()->getStartColor()->getRGB();
}
}
$newSpreadsheet = $this->writeAndReload($this->spreadsheet, 'Xls');
$newWorksheet = $newSpreadsheet->getActiveSheet();
foreach ($colours as $cellAddress => $expectedColourValue) {
$actualColourValue = $newWorksheet->getStyle($cellAddress)->getFill()->getStartColor()->getRGB();
self::assertSame($expectedColourValue, $actualColourValue);
}
}
}

View File

@ -0,0 +1,80 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Shared;
use PhpOffice\PhpSpreadsheet\Shared\Drawing;
use PhpOffice\PhpSpreadsheet\Style\Font;
use PHPUnit\Framework\TestCase;
class DrawingTest extends TestCase
{
/**
* @dataProvider providerPixelsToCellDimension
*/
public function testPixelsToCellDimension(
float $expectedResult,
int $pixelSize,
string $fontName,
int $fontSize
): void {
$font = new Font();
$font->setName($fontName);
$font->setSize($fontSize);
$result = Drawing::pixelsToCellDimension($pixelSize, $font);
self::assertSame($expectedResult, $result);
}
/**
* @dataProvider providerCellDimensionToPixels
*/
public function testCellDimensionToPixels(
int $expectedResult,
int $cellSize,
string $fontName,
int $fontSize
): void {
$font = new Font();
$font->setName($fontName);
$font->setSize($fontSize);
$result = Drawing::cellDimensionToPixels($cellSize, $font);
self::assertSame($expectedResult, $result);
}
public function providerPixelsToCellDimension(): array
{
return [
[19.9951171875, 100, 'Arial', 7],
[14.2822265625, 100, 'Arial', 9],
[14.2822265625, 100, 'Arial', 11],
[13.092041015625, 100, 'Arial', 12], // approximation by extrapolating from Calibri 11
[19.9951171875, 100, 'Calibri', 7],
[16.664341517857142, 100, 'Calibri', 9],
[14.2822265625, 100, 'Calibri', 11],
[13.092041015625, 100, 'Calibri', 12], // approximation by extrapolating from Calibri 11
[19.9951171875, 100, 'Verdana', 7],
[12.5, 100, 'Verdana', 9],
[13.092041015625, 100, 'Verdana', 12], // approximation by extrapolating from Calibri 11
[17.4560546875, 100, 'Wingdings', 9], // approximation by extrapolating from Calibri 11
];
}
public function providerCellDimensionToPixels(): array
{
return [
[500, 100, 'Arial', 7],
[700, 100, 'Arial', 9],
[700, 100, 'Arial', 11],
[764, 100, 'Arial', 12], // approximation by extrapolating from Calibri 11
[500, 100, 'Calibri', 7],
[600, 100, 'Calibri', 9],
[700, 100, 'Calibri', 11],
[764, 100, 'Calibri', 12], // approximation by extrapolating from Calibri 11
[500, 100, 'Verdana', 7],
[800, 100, 'Verdana', 9],
[764, 100, 'Verdana', 12], // approximation by extrapolating from Calibri 11
[573, 100, 'Wingdings', 9], // approximation by extrapolating from Calibri 11
];
}
}

View File

@ -2,6 +2,7 @@
namespace PhpOffice\PhpSpreadsheetTests\Worksheet; namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
use PhpOffice\PhpSpreadsheet\Helper\Dimension;
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@ -29,9 +30,18 @@ class ColumnDimensionTest extends TestCase
{ {
$expected = 1.2; $expected = 1.2;
$columnDimension = new ColumnDimension(); $columnDimension = new ColumnDimension();
$columnDimension->setWidth($expected); $columnDimension->setWidth($expected);
$result = $columnDimension->getWidth(); $result = $columnDimension->getWidth();
self::assertSame($expected, $result); self::assertSame($expected, $result);
$expectedPx = 32.0;
$expectedPt = 24.0;
$columnDimension->setWidth($expectedPx, Dimension::UOM_PIXELS);
$resultPx = $columnDimension->getWidth(Dimension::UOM_PIXELS);
self::assertSame($expectedPx, $resultPx);
$resultPt = $columnDimension->getWidth(Dimension::UOM_POINTS);
self::assertSame($expectedPt, $resultPt);
} }
public function testGetAndSetAutoSize(): void public function testGetAndSetAutoSize(): void

View File

@ -0,0 +1,55 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
use PhpOffice\PhpSpreadsheet\Helper\Dimension;
use PhpOffice\PhpSpreadsheet\Worksheet\RowDimension;
use PHPUnit\Framework\TestCase;
class RowDimensionTest extends TestCase
{
public function testInstantiateColumnDimensionDefault(): void
{
$expected = 0;
$rowDimension = new RowDimension();
self::assertInstanceOf(RowDimension::class, $rowDimension);
$result = $rowDimension->getRowIndex();
self::assertEquals($expected, $result);
}
public function testGetAndSetColumnIndex(): void
{
$expected = 2;
$rowDimension = new RowDimension();
$rowDimension->setRowIndex($expected);
$result = $rowDimension->getRowIndex();
self::assertSame($expected, $result);
}
public function testGetAndSetHeight(): void
{
$expected = 1.2;
$columnDimension = new RowDimension();
$columnDimension->setRowHeight($expected);
$result = $columnDimension->getRowHeight();
self::assertSame($expected, $result);
$expectedPx = 32.0;
$expectedPt = 24.0;
$columnDimension->setRowHeight($expectedPx, Dimension::UOM_PIXELS);
$resultPx = $columnDimension->getRowHeight(Dimension::UOM_PIXELS);
self::assertSame($expectedPx, $resultPx);
$resultPt = $columnDimension->getRowHeight(Dimension::UOM_POINTS);
self::assertSame($expectedPt, $resultPt);
}
public function testRowZeroHeight(): void
{
$expected = true;
$rowDimension = new RowDimension();
$rowDimension->setZeroHeight($expected);
$result = $rowDimension->getZeroHeight();
self::assertTrue($result);
}
}

View File

@ -77,4 +77,6 @@ return [
['exception', ''], ['exception', ''],
[48, 'B1'], [48, 'B1'],
[0, 'Q15'], [0, 'Q15'],
[52, '"21-Dec-2000", '],
[52, '"21-Dec-2000", null'],
]; ];

View File

@ -77,4 +77,8 @@ return [
's', 's',
'123456\n', '123456\n',
], ],
'Numeric that exceeds PHP MAX_INT Size' => [
's',
'1234567890123459012345689012345690',
],
]; ];

Binary file not shown.