Phpspreadsheet: getFormattedValue: invalid custom format value

Created on 14 Jul 2019  路  4Comments  路  Source: PHPOffice/PhpSpreadsheet

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?

Formatted value in accordance with the format 000\.00\.000\.0

Example: if value 11020011 and format code 000\.00\.000\.0 i wait formatted value 011.02.001.1

What is the current behavior?

Excel:
value 2010035
format 000\.00\.000\.0
dispay 002.01.003.5

PhpSpreadscheet:
value 2010035
format code 000\\.00\\.000\\.0
formatted value 2010035.00.2010035.00

What are the steps to reproduce?

Example Excel file https://drive.google.com/file/d/1P_3K_x-pL_GlW7xxBxZC3qgcYCFirzKr/view?usp=sharing

There is only one cell in the file with data 2010035 and format 000\.00\.000\.0

<?php

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

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($pFilename)->getActiveSheet();

echo $spreadsheet->getCellByColumnAndRow(1, 1)->getValue();
// 2010035

echo $spreadsheet->getCellByColumnAndRow(1, 1)->getStyle()->getNumberFormat()->getFormatCode();
// 000\\.00\\.000\\.0

echo $spreadsheet->getCellByColumnAndRow(1, 1)->getFormattedValue();
// 2010035.00.2010035.00

Which versions of PhpSpreadsheet and PHP are affected?

PHP 7.1
PhpSpreadscheet 1.6.0, 1.7.0, 1.8.2

Most helpful comment

resolved in master

All 4 comments

The problem is the . character; the code is only testing for the presence of a . without looking to see if it's escaped... it'll take me a while to modify the block of code that handles "special" formatting masks

resolved in master branch

resolved in master

@MarkBaker thanks! I checked on the master branch - it works as expected!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexbog8 picture alexbog8  路  4Comments

PowerKiKi picture PowerKiKi  路  4Comments

noxidsoft picture noxidsoft  路  3Comments

huglester picture huglester  路  5Comments

stratboy picture stratboy  路  5Comments