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

PHP spreadsheet not formatting cell correctly #343

Closed
garrettgjb opened this issue Jan 20, 2018 · 1 comment
Closed

PHP spreadsheet not formatting cell correctly #343

garrettgjb opened this issue Jan 20, 2018 · 1 comment

Comments

@garrettgjb
Copy link

garrettgjb commented Jan 20, 2018

Sorry reopening because I posted some invalid php and the old issue was closed.

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?

I expect for the column containing "Duration" should come in as "mm" format as defined in excel. Meaning it should look like an integer as you see when you are in excel.
screen shot 2018-01-19 at 9 07 59 pm

The column subtracts one date from another date.
I.e.

2018-01-22 02:00:00 PM - 2018-01-22 01:00:00 PM

We format is as [mm] so it would be 60.

I think what is happening is this library doesn't know how to do binary operations with dates. If you multiple the decimal number by 1440 you get the correct number. Or it isn't formatting it correctly.

What is the current behavior?

Duration column comes in as a decimal in the php code.
screen shot 2018-01-19 at 9 00 56 pm

What are the steps to reproduce?

Import the following file with phpspreadsheet:
importtest-phpspreadsheet.xlsx

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';

	$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();

	$file="importtest-phpspreadsheet.xlsx";
	$spreadsheet = $reader->load($file);
	$worksheet = $spreadsheet->getActiveSheet();

	echo "Should be 60";
	echo "\nActual: " . ($spreadsheet->getActiveSheet()->getCell('K2')->getFormattedValue());
	echo "\nFinished";

Current output:
Should be 60
Actual: 0.041666666671517

Expected output:
Should be 60
Actual: 60

If you open the spreadsheet in excel, cell K2 is in fact 60.

Which versions of PhpSpreadsheet and PHP are affected?

PHP 5.6, Latest phpspreadsheet from composer

@PowerKiKi
Copy link
Member

Duplicate of #342

@PowerKiKi PowerKiKi marked this as a duplicate of #342 Jan 21, 2018
@PHPOffice PHPOffice locked and limited conversation to collaborators Jan 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants