Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Spreadsheet::XLSX date format problem

by Bethany (Scribe)
on Jul 11, 2014 at 15:50 UTC ( [id://1093241]=note: print w/replies, xml ) Need Help??


in reply to Spreadsheet::XLSX date format problem

It seems to be the number of days since 12/30/1899? Is this a bug with the module?

No bug, that's how Excel stores dates. I've been dealing with this on a PHP-based Website, and naturally there's a Perl module for that.

http://search.cpan.org/~aburs/DateTime-Format-Excel-0.31/lib/DateTime/Format/Excel.pm

P.S.: To demonstrate that Excel actually stores the date as epoch days, open Excel and type 2014-07-11 (or any date in a format Excel recognizes as being a date) into a cell. Now format the cell as a generic number. 2014-07-11 becomes 41831.00. Date-time values get stored with the fraction of a day to the right of the decimal point.

P.P.S.: If you haven't got Excel, OpenOffice Calc behaves exactly the same way.

Replies are listed 'Best First'.
Re^2: Spreadsheet::XLSX date format problem
by Anonymous Monk on Jul 11, 2014 at 19:17 UTC
    You're right, the module did it, thanks!

      Yay! Have fun shooting the sheet. :-}

        Having a related issue. I am able to convert the date fine when I know it is a date. My issue is identifying the cell as a date when it has a custom date format. There is not an apparent way for me to know whether the cell is a date value to convert or an actual number as none of the cell attributes tells me it is a date. Excel cell has a custom number/date format of "mm/dd/yyyy" and a value of "07/20/2014". Code below shows my issue:
        my ( $cell, $col, $k, $row, $sheet ); my $workbook = Spreadsheet::XLSX->new( "test.xlsx" ); foreach $sheet ( @{ $workbook->{Worksheet} } ) { $sheet->{MaxRow} ||= 0; #$sheet->{MinRow}; $sheet->{MaxCol} ||= 0; #$sheet->{MinCol}; next if ( $sheet->{MaxRow} == 0 and $sheet->{MaxCol} == 0 ); foreach $row ( $sheet->{MinRow} .. $sheet->{MaxRow} ) { foreach $col ( $sheet->{MinCol} .. $sheet->{MaxCol} ) { $cell = $sheet->{Cells}[$row][$col]; if ($cell) { foreach $k ( keys %{$cell} ) { print "cell{$k}=$cell->{$k}\n"; } } } } } Results: cell{Type}=Numeric cell{Val}=41840 cell{_Value}=41840 cell{Format}=
        In the original Spreadsheet::ParseExcel the $cell{Type} attribute above returns "Date".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1093241]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-20 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found