Skip to content
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

Xlsx Writer corrupts decimal values with commas in them #1281

Closed
makedin opened this issue Dec 10, 2019 · 1 comment
Closed

Xlsx Writer corrupts decimal values with commas in them #1281

makedin opened this issue Dec 10, 2019 · 1 comment

Comments

@makedin
Copy link
Contributor

makedin commented Dec 10, 2019

This is:

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

What is the expected behavior?

Decimal values should be represented correctly (like "1.1") in Xlsx files.

What is the current behavior?

If PHP has been set to use a locale that uses comma as decimal separator, any decimal values (floats, real numbers) with a decimal part become corrupted: "1,1" (1.1) for instance becomes "1.1.0".

Note that LibreOffice Calc silently fixes values like these. Neither Microsoft Excel nor Google Sheets handle these values as decimals (Excel gives a warning and converts the value to a string. Sheets drops the value silently). PhpSpreadsheet itself silently converts the value to a string.

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

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

if (!setlocale(LC_ALL, 'fi_FI.UTF-8')) {
  die("Locale not available, this isn't going to work\n"); 
} 

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$spreadsheet->getActiveSheet()->setCellValue('A1', 1.1);

$filename = 'decimalcomma.xlsx';
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($filename);          

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($filename);
echo($spreadsheet->getActiveSheet()->getCell('A1')->getValue());

Which versions of PhpSpreadsheet and PHP are affected?

The bug seems to have been introduced by cf30c2a. It should manifest with any supported PHP version.

@MarkBaker
Copy link
Member

Thank you for highlighting this issue, and for the resolution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants