Skip to content
This repository has been archived by the owner on Jan 2, 2019. It is now read-only.

Simple calculation in formatted date cell returns empty string #437

Closed
ncrypthic opened this issue Sep 18, 2014 · 2 comments
Closed

Simple calculation in formatted date cell returns empty string #437

ncrypthic opened this issue Sep 18, 2014 · 2 comments

Comments

@ncrypthic
Copy link

Hi,

I have following fixed format date cell (DD-MM-YYYY)

No A B C
1 06-09-2014 16-09-2014 26-09-2014

with actual cell values

  • A1 '09/06/2014'
  • B1 '=A1+10'
  • C1 '=B1+10'

when I try to get the cell value for B1 and C1 using var_dump($cell->getValue()); I get empty string ''

But when I changed the formula to =INT(cell_address)+10 in cell B1 and C1 I get correct excel serialized date values:

  • B1: 41908
  • C1: 41918

Can somebody advise on how correct the calculation behavior?

Cheers,
Lim

@ncrypthic
Copy link
Author

After digging around I found this

When creating excel file using Ms Excel 2013, the sheet.xml looks like this

<row r="1" spans="1:2" x14ac:dyDescent="0.25">
    <c r="A1" s="1">
        <v>42095</v>
    </c>
    <c r="B1" s="1">
        <f>A1+7</f>
        <v>42102</v>
    </c>
</row>

While using Libreoffice Spreadsheet the sheet.xml looks this

<row collapsed="false" customFormat="false" customHeight="false" hidden="false" ht="12.1" outlineLevel="0" r="1">
    <c r="A1" s="1" t="n">
        <v>42095</v>
    </c>
    <c r="B1" s="1" t="inlineStr">
        <f aca="false">A1+7</f>
        <is>
            <t>
            </t>
        </is>
    </c>
</row>

The attributes t="inlineStr" in sheet.xml produces by Libreoffice spreadsheet makes PHPExcel loader read the cell as inline string and ignoring the ```

https://github.com/PHPOffice/PHPExcel/blob/develop/Classes/PHPExcel/Reader/Excel2007.php#L850-L853

Can we check for <f/> element just to be sure before using inlineStr dataType like sample below ?

case "inlineStr":
    if(isset($c->f)) {
        $this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToError');
    } else {
        $value = $this->_parseRichText($c->is);
    }
    break;

@MarkBaker
Copy link
Member

Thanks for the fix, now implemented

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants