Menu

#35 Time-formatted cells parse improperly

open
nobody
None
5
2005-09-27
2005-09-27
No

Cells formatted as "Time" (using any of the top 5
formatting styles) do not parse properly.

When run through the parser the result of a
Time-formatted cell is a decimal value.

For example:
A cell formatted as "Time" with the value:
1:00:00 PM

When parsed comes out as:
0.041666666666667

I was expecting the parsed value to be the same as the
cell value - "1:00:00 PM" - however, it appears as
though some sort of math calculation is being done.

Formatting the cell as "General" or even "Custom"
parses correctly.

Asking end users to make sure their Excel sheets don't
contain any Time-formatted cells is asking quite a bit.

Otherwise, all other cell formats I've come across from
end users have parsed as expected.

Discussion

  • conti gian enrico

    Logged In: YES
    user_id=344848

    I got ther same result.
    I traced down source code: it parses time as it wuold be a DOUBLE.
    I found it near line 618, when unpacking.

     
  • Nobody/Anonymous

    Logged In: NO

    I had the same problem; the following change in createDate
    solves it for me at least:

    --- reader.php 2006-09-13 12:30:01.878902328 +0200
    +++ reader.php.ant9000 2006-09-13 12:29:34.679037336 +0200
    @@ -610,7 +610,6 @@
    }
    $raw = $this->createNumber($spos);
    $string = sprintf($this->curformat,
    $raw * $this->multiplier);
    -
    // $this->addcell(NumberRecord($r));
    }
    $this->addcell($row, $column, $string,
    $raw);
    @@ -720,7 +719,9 @@
    $raw = $numValue;
    $hours = floor($numValue * 24);
    $mins = floor($numValue * 24 * 60) - $hours * 60;
    - $secs = floor($numValue *
    Spreadsheet_Excel_Reader_msInADay) - $hours * 60 * 60 -
    $mins * 60;
    +// Ant9000 - 2006/09/13 11:48 - Changed floor to round to
    correct datetime cells
    +// $secs = floor($numValue *
    Spreadsheet_Excel_Reader_msInADay) - $hours * 60 * 60 -
    $mins * 60;
    + $secs = round($numValue *
    Spreadsheet_Excel_Reader_msInADay) - $hours * 60 * 60 -
    $mins * 60;
    $string = date ($this->curformat,
    mktime($hours, $mins, $secs));
    }
    return array($string, $raw);

     

Log in to post a comment.

MongoDB Logo MongoDB