Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Reading excel file using PERL

by Anonymous Monk
on Aug 14, 2009 at 19:56 UTC ( #788736=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Perl to parse through an Excel file and I'm having trouble with a date field. The date displays as 8/14/2009 (mm/dd/yyyy)but when the script runs it is printing as "Win32::OLE::Variant=SCALAR(0x2626704)" for value and 36756 for formula. Is there any way to read the date field and print it as date format (dd/mm/yyyy)?

Replies are listed 'Best First'.
Re: Reading excel file using PERL
by n3toy (Hermit) on Aug 14, 2009 at 20:08 UTC

    Excel stores the date as a serial date, which is different from how it displays dates.

    DateTime::Format::Excel may be of help to you.

Re: Reading excel file using PERL
by graff (Chancellor) on Aug 15, 2009 at 00:58 UTC
    Are you using Spreadsheet::ParseExcel? If so, how are you using it? (In other words: show us some relevant perl code.) If you're not using that, what are you using? (That is, show us some code.)
      Hi,

      I am using Win32::OLE to read from the excel file.
      printf "At ($row, $col) the value is %s\n", $Sheet->Cells($row,$col)->{'Value'};
        I don't know about Win32::OLE, but with Spreadsheet::ParseExcel, you have your choice of getting the (unformatted) "Val" or the (formatted) Value for each cell (and you'll want to choose the latter, though the date format you get will depend on how the spreadsheet was set up). Using the module's OO-style interface, it's a difference between a hash value and a method call:
        #!/usr/bin/perl use strict; use warnings; use Spreadsheet::ParseExcel; my $Usage = "Usage: $0 filename.xls\n"; die $Usage unless ( @ARGV == 1 and -f $ARGV[0] ); my $xcl = Spreadsheet::ParseExcel::Workbook->Parse( $ARGV[0] ); for my $sheet ( @{$xcl->{Worksheet}} ) { printf( "Sheet: %s\n", $sheet->{Name} ); for my $row ( $sheet->{MinRow} .. $sheet->{MaxRow} ) { for my $col ( $sheet->{MinCol} .. $sheet->{MaxCol} ) { my $cell = $sheet->{Cells}[$row][$col]; printf( " row %s, col %s: unformatted= %s, formatted= %s\n +", $row, $col, $cell->{Val}, $cell->Value ); } } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2023-09-24 15:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?