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

Error retrieving formula result #1622

Open
roger23e opened this issue Aug 21, 2020 · 5 comments
Open

Error retrieving formula result #1622

roger23e opened this issue Aug 21, 2020 · 5 comments

Comments

@roger23e
Copy link

roger23e commented Aug 21, 2020

This is:

- [X] a bug report
- [X] 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?

Im reading a xlsx file column, this column contain a formula if y use getCalculatedValue() y wamt to receive the same value the spreadsheet has.

What is the current behavior?

i receive a different value

What are the steps to reproduce?

read the file with PhpSpreadsheet and get the cell K30 from the first sheet with the function getCalculatedValue()

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

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

// add code that show the issue here...
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader("Xlsx");

$reader->setReadDataOnly(true);

$spreadsheet = $reader->load("Calculos sept-2013.xlsx");

$k = $spreadsheet->getActiveSheet()->getCell('K30')->getCalculatedValue();
  
echo "the var k contains: ".$k." and in the excel the cell K30 have 42";



### Which versions of PhpSpreadsheet and PHP are affected?
PhpSpreadsheet 1.14
Php 7.4.2
@MarkBaker
Copy link
Member

So what is the formula in cell K30? What is the value that you are getting when you call getCalculatedValue()? What are the values of cells that are reerenced in the formula?

@roger23e
Copy link
Author

Hello, thank you for your response, im going to attach the file DEMOXLSX.xlsx, the formula is like follow:

=SI(O(B30>1;B30=1);REDONDEAR(I30*(POTENCIA((1+$X$18/100);$U$17));0);"")

on the excel the result is 42 but in phpspreadsheet getCalculatedValue() return 13
DEMOXLSX.xlsx

@roger23e
Copy link
Author

So what is the formula in cell K30? What is the value that you are getting when you call getCalculatedValue()? What are the values of cells that are reerenced in the formula?

Hello, thank you for your response, im going to attach the file DEMOXLSX.xlsx, the formula is like follow:

=SI(O(B30>1;B30=1);REDONDEAR(I30*(POTENCIA((1+$X$18/100);$U$17));0);"")

on the excel the result is 42 but in phpspreadsheet getCalculatedValue() return 13
DEMOXLSX.xlsx
DEMOXLSX.xlsx

@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If this is still an issue for you, please try to help by debugging it further and sharing your results.
Thank you for your contributions.

@stale stale bot added the stale label Dec 25, 2020
@oleibman
Copy link
Collaborator

oleibman commented Sep 3, 2022

Confirming - this is still a problem.

@stale stale bot removed the stale label Sep 3, 2022
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue May 16, 2024
Investigating issue PHPOffice#1622, I found that its extremely complicated formula, which had been leading to an incorrect result, now led to an exception. I am able to fix the exception; unfortunately, I am no closer to resolving the original issue. So I'll apply the baby step while continuing to investigate. Function POWER had changed from untyped args to a defined set of types. The set of types was determined according to the doc block, but that was incomplete - it had neglected to include `null` and `bool`. This PR corrects the function prototype and the doc block, and adds the missing tests for those conditions.
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

3 participants