AhmadFais1611 / php-excel-reader

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

Date/Time fields come back as literal "M/d/yyyy h:mm:ss AM/PM" #65

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

starting with:
$data = new Spreadsheet_Excel_Reader("example.xls");

1. A column where it's contents viewed in Excel might be "2/23/2010 
9:59:20 PM" comes back from the call as a literal "M/d/yyyy h:mm:ss AM/PM"

2. All text valued columns are being intrepreted correctly

3. Dollar valued fields are coming back "doubled/tripled" for example the 
value $1,070.00 comes back from the call as [$$-1,0701,0701,0701,070]
1,0701,0701,0701,070.1,0701,070);([$$-1,0701,0701,0701,070]
1,0701,0701,0701,070.1,0701,070)

4. A plain numeric field such as 159 is coming back from the call as 
159159159159 

Please provide any additional information below.
The Row/column stat count functions work but the "type" and "raw" 
functions do not work.  Help!  I really wanted to work with this class.  
Thanks! Jay

Original issue reported on code.google.com by j...@jay-pennington.com on 23 Feb 2010 at 10:53

GoogleCodeExporter commented 8 years ago
I am having the same issue, and it's become extremely frustrating. Can someone 
please help with this?

Original comment by da...@lemcoe.com on 21 Aug 2012 at 3:48

GoogleCodeExporter commented 8 years ago
I'm having the same problem. I saw the datatype is "adapted", and not the 
standard Date-datatype... Help?

Original comment by philip.d...@gmail.com on 17 Sep 2012 at 9:36

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi, I'm a little late to this party but it looks like this issue is still open 
and I have a solution for the those who need a quick and dirty fix.

I'm not sure why this happens but here is what happened in my case. I was 
trying to parse an xls file created by Crystal Report software. Its an xls file 
but the date was coming back mm/dd/yyyy instead of as a date... 

If you open the script and go to line 1610(ish) there is a function called 
_getCelDetails.  Most likely your cel $type variable will be 'other'.  

Excel formats the date as a number of days since 12-30-1899 basically you'll 
get a number like 41XXX as the 'raw' data from the date column.

http://code.google.com/p/php-excel-reader/issues/detail?id=42 for more.. 

Here is my fix, I put this code in right before the return array in the 
_getCelDetails function, you can do whatever...

if($type == 'other'){

 if(is_numeric( $numValue ) && floor( $numValue ) != $numValue){
// echo " Decimal".$numValue."<br> "; 
//this is time value, idk what to do with it and I don't need it but if it's in 
decimal format it's date / time.  
}else{
//it's not a decimal.....
$timestamp = ($numValue - 25565) * 86400;  // (25565) Subtract date from dec 
30, 1899 but strtotime wont parse dates before 1900 or 1970 depending on php 
versions and what not. So this number is by hand and may need adjusting...

$string = date("m/d/Y", $timestamp);

}
}

This fixed it for my particular issue but it would not work for everyone, but 
hopefully this gives you a starting point to make changes to suit your 
particular needs until it's fixed properly. Edit: I endeded up just reusing the 
code for the if($type = 'date'){ to format dates and times..

Original comment by binxa...@gmail.com on 20 Aug 2013 at 4:33