bastiam / php-excel-reader2

Automatically exported from code.google.com/p/php-excel-reader2
0 stars 0 forks source link

Time values are not read correct after upgrade to 2.22 #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Upgraded to 2.22
2. Import excel file
3. Printed raw, val and type values

What is the expected output? What do you see instead?
Time column data results return 02:00 no matter what time data is stored.

What version of the product are you using? On what operating system?
Ubuntu / 2.22

Please provide any additional information below.
After upgrading to 2.22 to solve encoding problem reader doesn't read time
data correctly. Data on excel file is 06:00, after reading raw() returns
0.25, val() returns 02:00. Excel file cell format for that column is
hour:minutes and same excel file didn't have any problems with previous
version. 

Original issue reported on code.google.com by blockedm...@gmail.com on 6 May 2010 at 8:57

GoogleCodeExporter commented 8 years ago
I have same error (bug) on 2.21 version: all time columns (HH:MM) after reading 
returns 02:00.

Also dump function returns 02:00 in all columns that have data in HH:MM format

Original comment by shade...@gmail.com on 12 Aug 2010 at 1:49

GoogleCodeExporter commented 8 years ago
I fix it!!! (Sorry for my bad english - i`m from ukraine)

First of all go to line 1527 excel_reader2.php and replace 
'rectype' => $rectype,
 to 
'type' => $rectype,

After it i write small function in class Spreadsheet_Excel_Reader:

function dumptoarray_noformat($sheet=0) {
        $arr = array();
        for($row=1;$row<=$this->rowcount($sheet);$row++){
                for($col=1;$col<=$this->colcount($sheet);$col++){
                    $val = trim($this->raw($row, $col, $sheet));
            if ($val==''){$val = $this->val($row,$col,$sheet);}
                    $arr[$row][$col] = $val;
                }
    }                        
        return $arr;
}

This function dump all values from excel document into array.
Now you can see results by typing:
$data = new Spreadsheet_Excel_Reader($file,true,'utf-8');
$my_arr = $data->dumptoarray_noformat();
echo "<pre>";
print_r($my_arr);

=====================

But now, all column values, that have data in HH:MM format - looks like 
0.239583333333  or 0.659722222222 :)

Its a decimal value of a time.
To convert in into a normal format, use this command:

$test_val = "0.315972222222";
$normal_time = date('H:i', mktime(0,0,0)+86400*$test_val);

I hope that I have someone able to help

Original comment by shade...@gmail.com on 12 Aug 2010 at 2:29