-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Not formatting cell correctly with [MM
] code
#342
Comments
The code provided is not valid PHP code and cannot be run. And even if it could it would not show anything useful regarding this issue. Anyway the described behavior is the expected behavior. The value you got are indeed the values stored in the file. What you see in Excel is not the raw values, but formatted value. You should have a look at |
Please check again. I updated the code so it is runnable, just put the spreadsheet in the same dir. Output: My previous example called toArray with no params which my research showed should have formatted. In my updated sample, I have called getFormattedValue as you said so you can see its not working. |
I've reposted the issue here since this one is closed: |
[MM
] code
@PowerKiKi Can this issue be reopened? I'm guessing you were able to recreate it since you changed the title. |
Please refrain from opening new issue for the same problem, we can continue the discussion here and re-open as needed. The MCVE should not rely on an external file and the code should have been simplified down to: <?php
require __DIR__ . '/vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
var_dump(NumberFormat::toFormattedString(0.041666666671517, '[MM]')); |
@PowerKiKi sorry, I'm new to github issue reporting process and didn't realize the problem was with toFormattedString. |
I did a little debugging and it looks like in an attempt to remove color information, we clear out the format variable so it doesn't go into the date format code. From toFormattedString:
I'm not an expert and regexp's and I don't know what color formatting looks like or I would attempt a fix. |
I suggest you add a case for colors in The following page should help you find out what syntaxes should be supported: https://support.office.com/en-us/article/create-or-delete-a-custom-number-format-78f2a361-936b-4c03-8772-09fab54be7f4 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
When using format `[h]:mm` it should convert to the "total hours:minutes" Closes PHPOffice#666 Fixes PHPOffice#664 Fixes PHPOffice#446 Fixes PHPOffice#342
Fixed by 699da09 |
This is:
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.
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.
What is the current behavior?
Duration column comes in as a decimal in the php code.
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:
toArray return will have incorrect values.
Which versions of PhpSpreadsheet and PHP are affected?
PHP 5.6, Latest phpspreadsheet from composer
The text was updated successfully, but these errors were encountered: