Update documentation with details of changes to the StringValueBinder
This commit is contained in:
parent
504ed9a87c
commit
488701b748
|
|
@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
|
|||
|
||||
### Added
|
||||
|
||||
- Nothing.
|
||||
- More flexibility in the StringValueBinder to determine what datatypes should be treated as strings [PR #2138](https://github.com/PHPOffice/PhpSpreadsheet/pull/2138)
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
|||
|
|
@ -559,12 +559,24 @@ $spreadsheet->getActiveSheet()->setCellValue('B5', '21 December 1983');
|
|||
```
|
||||
|
||||
Alternatively, a `\PhpOffice\PhpSpreadsheet\Cell\StringValueBinder` class is available
|
||||
if you want to preserve all string content as strings. This might be appropriate if you
|
||||
if you want to preserve all content as strings. This might be appropriate if you
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue