-
-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reader: Any way to retrieve the Excel number format string or other form of number format? #220
Comments
Not from me, but any PR is welcome 💪 |
Know anyone who could do the work? I don't have the skill set but would be willing to reimburse for effort spent! |
Can you give me a sample and the output you expect from the method? I'll see if I can implement what you are looking for, and I'll give you my quote |
Sure - I've attached an example file with a variety of formattings, and here is some code and the output: use \PhpOffice\PhpSpreadsheet\IOFactory;
$ppsType = IOFactory::identify($filepath);
$reader = IOFactory::createReader($ppsType);
$spreadsheet = $reader->load($filepath);
$worksheet = $spreadsheet->getSheet(0);
$highestRow = $worksheet->getHighestRow();
$formatStr = "%3s %20s %15s %15s %35s\n ";
print(sprintf($formatStr, 'row#', 'getValue', 'type', 'formattedValue', 'formatCode'));
for ($row = 1; $row <= $highestRow; $row++) {
$cell = $worksheet->getCellByColumnAndRow(1, $row);
$value = $cell->getValue();
$type = gettype($value);
$formatCode = $cell->getStyle()->getNumberFormat()->getFormatCode();
print(sprintf($formatStr,
$row,
$value,
$type,
$cell->getFormattedValue(),
$formatCode,
));
} Which outputs:
There are probably more examples there than necessary :-) Essentially what I'm looking for is the same ability to get both the raw (typed) value from getFormattedValue() would be a nice to have if it is simple, assuming the formatted value is also stored in the XML and not rendered by PHPSpreadsheet / Excel? |
As far as I can tell, the PhpSpredsheet had to hard-code them to have them available: https://github.com/PHPOffice/PhpSpreadsheet/blob/0c37ae2c30599819d7fab7d13ab5027ffd71f61a/src/PhpSpreadsheet/Style/NumberFormat.php#L301 It is not my intention to provide any data that's not already in the files, with this package. |
I agree entirely, there is no point in making that mapping - I would rather interpret directly from the raw numeric code in that case too, and I will update my PHPSpreadsheet-based code to use getBuiltInFormatCode() instead. |
I've tried ingesting an Excel file with various number formattings (percentage, roundings, currency) and I am trying to do the equivalent of PHPSpreadsheet:
I can see there are methods getFormat() and getStyleId() on Style, but these just return null and -1 respectively, independent of the actual formatting.
I guess #174 is also pointing to this.
Any plans to implement?
The text was updated successfully, but these errors were encountered: