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

some columns get a wrong formula when imported from a xls file #1570

Closed
rewalax opened this issue Jul 5, 2020 · 2 comments · Fixed by #4140
Closed

some columns get a wrong formula when imported from a xls file #1570

rewalax opened this issue Jul 5, 2020 · 2 comments · Fixed by #4140

Comments

@rewalax
Copy link

rewalax commented Jul 5, 2020

This is:

- [ phpspreadsheet] a bug report

What is the expected behavior?

when i imported data from a normal xls file, some columns get a wrong formula(not only wrong calculated result but also wrong formula expression) :

this is the write formula in the original xls file:
image

What is the current behavior?

this is what it got after imported with phpspreadsheet
image

but some other formula was just right, I dont why. pls help me out.

What are the steps to reproduce?

<?php
// some code here...
$inputFileType = \PhpOffice\PhpSpreadsheet\IOFactory::identify($filename); 

$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType); 
$reader->setReadDataOnly(true);
$spreadsheet = $reader->load($filename);  
$worksheet = $spreadsheet->getActiveSheet();   
$sheetAllCount = $spreadsheet->getSheetCount(); 
for ($index = 0; $index < $sheetAllCount; $index++) {   
    $title[] = $spreadsheet->getSheet($index)->getTitle();
}
\PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance($spreadsheet)->disableCalculationCache();
\PhpOffice\PhpSpreadsheet\Calculation\Calculation::getInstance($spreadsheet)->clearCalculationCache();

$sheet = $spreadsheet->getSheet($whatTable); 

$highest_row = $sheet->getHighestRow(); 

$highest_column = $sheet->getHighestColumn(); 

$highestColumnIndex = Coordinate::columnIndexFromString($highest_column);  
for ($i = 1; $i <= $highestColumnIndex; $i++) {
    for ($j = 1; $j <= $highest_row; $j++) {

        $conent = $sheet->getCellByColumnAndRow($i, $j)->getValue();
        //$conent = $sheet->getCellByColumnAndRow($i, $j)->getCalculatedValue();
        // $conent = $sheet->getCellByColumnAndRow($i, $j)->getCalculatedValue();

        $info[$j][$i] = $conent;
    }
}
var_dump($info);exit;

Which versions of PhpSpreadsheet and PHP are affected?

latest 1.14.0

@stale
Copy link

stale bot commented Sep 5, 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 Sep 5, 2020
@stale stale bot closed this as completed Sep 12, 2020
oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Aug 13, 2024
This supersedes PR PHPOffice#607 by @christian-forgacs, who deserves all the credit for reporting the problem and devising the solution. The PR went stale in 2018, and it is just easier to resubmit a clean version rather than clean up the old one. Among the suggestions in the PR was that you should try to create a spreadsheet from scratch to demonstrate the problem rather than supply one. However, my attempts to match the failing spreadsheet do not have a problem when they are read. So, a supplied spreadsheet it is.

Fix PHPOffice#1570. No sample spreadsheet was supplied with that issue, but I am almost certain that this is another example of the same problem. I am removing the stale label from that issue; it will be closed properly when this PR is merged.
@oleibman
Copy link
Collaborator

Should be fixed by PR #4140.

@oleibman oleibman reopened this Aug 13, 2024
@stale stale bot removed the stale label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants