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

Or mebbe, printing and otherwise manipulating date fields from Excel in perl. I can read in a date/value two column Range in an (very basic) excel spreadsheet, but when I try to print out the date column, it prints as a horrible Win32::OLE::Variant=SCALAR(0x196a838) sort of output. So, how can I turn this into a perl variable I can work with and understand? Any help and poitners gratefully received.... Bill

Replies are listed 'Best First'.
Re: reading Excel dates?
by Anonymous Monk on May 21, 2004 at 14:48 UTC
    Hi Bill, I had this problem too so try something like this:
    my $dateVar = $worksheet->Cells( $row, $col )->{Value}; if ( ref $dateVar ) { $theDate = $dateVar->ChangeType(VT_BSTR)->Value(); }
    Hopefully, that works for you. Michael
      ta for that. Looks like what I want (but I'll try it forst before confirming! :-) ) Bill
Re: reading Excel dates?
by Grygonos (Chaplain) on May 21, 2004 at 14:41 UTC

    Could you provide an example of your code? I'm confused by "date/value two column Range". Should it not be a single cell? (which Range objects can be used to acquire the value of) for example

    my $date = $sheet->Range("A1")->{Value}; print $date."\n"
    Please post your example code and I'll take a better look at what you're attempting.

      Sorry... I should make it clear I meant I have a 2-column Excel spreadsheet with column A being formatted as a Date and column B being formatted as a number. I can read it all into perl without any problems, but when I look at the eprl $vars, the B column of numbers indeed looks like numbers, but the column A date looks umm, some sort of horrible ref. which I don't understand. Cheers Bill