StringValueBinder.php 694 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet\Cell;
  3. use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
  4. class StringValueBinder implements IValueBinder
  5. {
  6. /**
  7. * Bind value to a cell.
  8. *
  9. * @param Cell $cell Cell to bind value to
  10. * @param mixed $value Value to bind in cell
  11. *
  12. * @throws \PhpOffice\PhpSpreadsheet\Exception
  13. *
  14. * @return bool
  15. */
  16. public function bindValue(Cell $cell, $value)
  17. {
  18. // sanitize UTF-8 strings
  19. if (is_string($value)) {
  20. $value = StringHelper::sanitizeUTF8($value);
  21. }
  22. $cell->setValueExplicit((string) $value, DataType::TYPE_STRING);
  23. // Done!
  24. return true;
  25. }
  26. }