PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.32k stars 3.45k forks source link

getFormattedValue() returns 0 for spreadsheet with complicated calculations involving VLOOKUP #1624

Closed JeyjooMilano closed 2 years ago

JeyjooMilano commented 4 years ago

This is:

- [ ] a bug report

What is the expected behavior?

getFormattedValue() and getCalculatedValue() should return a whole number

What is the current behavior?

getCalculatedValue(), getFormattedValue() both return 0 for complicated excel calculations that use conditional lookups.

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

// Create new Spreadsheet object

// add code that show the issue here...
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load("Lookup.xlsx"); // Simplified version of spreadsheet attached. Exhibits the problem
$sheet = $spreadsheet->getActiveSheet();

$v = $sheet->getCell('A5')->getValue();
$fv = $sheet->getCell('A5')->getFormattedValue();
$cv = $sheet->getCell('A5')->getCalculatedValue();

echo "getValue: ".$v;// =ROUND(VLOOKUP(A4,IF($A$2<55,$B$1:$I$4,$B$5:$I$8),$A$1+1,0)*$A$3/1000,2)
echo "<br>getFormattedValue: ".$fv;// 0
echo "<br>getCalculatedValue: ".$fv;// 0

Lookup.xlsx

Which versions of PhpSpreadsheet and PHP are affected?

Problem observed using PhpSpreadsheet 1.14.1 and PHP 7.3

stale[bot] commented 3 years ago

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.

oleibman commented 2 years ago

Code sample above now returns same result as Excel, 931.4. Closing ticket.