profile
viewpoint

Ask questionsCell::getValue() does not return raw value with numbers

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

In any case, the method Cell::getValue() should not cast the value of the cell but should return only string value as stored in the file.

The int/float value should be given only in the method Cell::getFormattedValue().

What is the current behavior?

Cell::getValue() casts the value of cell as integer/float even if the cell contents digits that not represent a number.

That causes also a lost of precision with big int.

What are the steps to reproduce?

<?php
require __DIR__ . '/vendor/autoload.php';

$value = '10210303648605466'; //this is not a number but a string

$filePath = __DIR__ . '/example.csv';
file_put_contents($filePath, $value);

$spreadSheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath);

var_dump($spreadSheet->getActiveSheet()->getCell('A1')->getValue() === $value); //should be bool(true) but display bool(false)

Which versions of PhpSpreadsheet and PHP are affected?

My env:

- PHP:7.2.1-1+ubuntu14.04.1+deb.sury.org+1PHP
- phpoffice/phpspreadsheet:1.0.0
PHPOffice/PhpSpreadsheet

Answer questions riconeitzel

… and if you want to create a custom version of the XLSX reader YOU HAVE TO COPY THE WHOLE CLASS because WAY TOO MUCH used methods are … PRIVATE!!! 😂

But yeah - it works!

useful!
source:https://uonfu.com/
Github User Rank List