Skip to content

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

@rewalax

Description

@rewalax

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions