Merge pull request #2878 from PHPOffice/Issue-2868_Emphasis-Documentation-for-setValueExplict

Update docblock documentation for setting cell values explicit
This commit is contained in:
Mark Baker 2022-06-10 14:37:24 +02:00 committed by GitHub
commit e3471f8a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Changed
- Better enforcement of value modification to match specified datatype when using setValueExplicit()
- Relax validation of merge cells to allow merge for a single cell reference [Issue #2776](https://github.com/PHPOffice/PhpSpreadsheet/issues/2776)
- Memory and speed improvements, particularly for the Cell Collection, and the Writers.
See [the Discussion section on github](https://github.com/PHPOffice/PhpSpreadsheet/discussions/2821) for details of performance across versions

View File

@ -202,6 +202,11 @@ class Cell
*
* @param mixed $value Value
* @param string $dataType Explicit data type, see DataType::TYPE_*
* Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
* method, then it is your responsibility as an end-user developer to validate that the value and
* the datatype match.
* If you do mismatch value and datatpe, then the value you enter may be changed to match the datatype
* that you specify.
*
* @return Cell
*/
@ -210,7 +215,7 @@ class Cell
// set the value according to data type
switch ($dataType) {
case DataType::TYPE_NULL:
$this->value = $value;
$this->value = null;
break;
case DataType::TYPE_STRING2:

View File

@ -48,7 +48,7 @@ class DataType
*
* @param null|RichText|string $textValue Value to sanitize to an Excel string
*
* @return null|RichText|string Sanitized value
* @return RichText|string Sanitized value
*/
public static function checkString($textValue)
{
@ -58,7 +58,7 @@ class DataType
}
// string must never be longer than 32,767 characters, truncate if necessary
$textValue = StringHelper::substring($textValue, 0, 32767);
$textValue = StringHelper::substring((string) $textValue, 0, 32767);
// we require that newline is represented as "\n" in core, not as "\r\n" or "\r"
$textValue = str_replace(["\r\n", "\r"], "\n", $textValue);

View File

@ -1177,6 +1177,11 @@ class Worksheet implements IComparable
* or as an array of [$columnIndex, $row] (e.g. [3, 5]), or a CellAddress object.
* @param mixed $value Value of the cell
* @param string $dataType Explicit data type, see DataType::TYPE_*
* Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
* method, then it is your responsibility as an end-user developer to validate that the value and
* the datatype match.
* If you do mismatch value and datatpe, then the value you enter may be changed to match the datatype
* that you specify.
*
* @return $this
*/
@ -1199,6 +1204,11 @@ class Worksheet implements IComparable
* @param int $row Numeric row coordinate of the cell
* @param mixed $value Value of the cell
* @param string $dataType Explicit data type, see DataType::TYPE_*
* Note that PhpSpreadsheet does not validate that the value and datatype are consistent, in using this
* method, then it is your responsibility as an end-user developer to validate that the value and
* the datatype match.
* If you do mismatch value and datatpe, then the value you enter may be changed to match the datatype
* that you specify.
*
* @return $this
*/
@ -1770,6 +1780,10 @@ class Worksheet implements IComparable
$numberRows = $lastRow - $firstRow;
$numberColumns = $lastColumnIndex - $firstColumnIndex;
if ($numberRows === 1 && $numberColumns === 1) {
return $this;
}
// create upper left cell if it does not already exist
$upperLeft = "{$firstColumn}{$firstRow}";
if (!$this->cellExists($upperLeft)) {