Reading time from an excel sheet.

Discussion in 'Perl Misc' started by rajendra, Jul 3, 2007.

  1. rajendra

    rajendra Guest

    Hello All,

    There is an excel sheet which has list of events given in time. I'm trying
    to read this time using win32 module
    When I do so, I get the time in General format (0.36525874).
    But I want to read in hh-mm-ss. How can I achieve this?.

    With Rgds,
    Raj
    rajendra, Jul 3, 2007
    #1
    1. Advertising

  2. rajendra

    Chad Hanna Guest

    rajendra wrote:
    > Hello All,
    >
    > There is an excel sheet which has list of events given in time. I'm trying
    > to read this time using win32 module
    > When I do so, I get the time in General format (0.36525874).
    > But I want to read in hh-mm-ss. How can I achieve this?.
    >
    > With Rgds,
    > Raj
    >
    >


    Do have a look at the Win32::OLE::Variant docs but my date purposes I
    use something like this:

    if (ref($field)) {
    if ($field->isa("Win32::OLE::Variant")) {
    if ($field->Type == VT_DATE) {
    $field = $field->Date("d MMM yyyy");
    }
    else {
    warn $field->Type, " Variant type at $row_no $sheet_name\n";
    }
    }
    else {
    warn ref($field), " reference at $row_no in $sheet_name\n";
    }
    }

    This allows me to cope with dates before and after 1900.


    --
    Chad Hanna
    Systems Developer FamilyHistoryOnline www.familyhistoryonline.net
    FreeBSD Apache MySQL Perl mod_perl PHP
    Chad Hanna, Jul 3, 2007
    #2
    1. Advertising

  3. rajendra <> wrote:
    > Hello All,


    > There is an excel sheet which has list of events given in time. I'm trying
    > to read this time using win32 module
    > When I do so, I get the time in General format (0.36525874).
    > But I want to read in hh-mm-ss. How can I achieve this?.


    You could do the math yourself. Excel store time/date events in days
    since Jan 0, 1900. So if you're just dealing with times (not dates),
    just multiply by 86400 (seconds in a day) to get it in seconds since
    midnight.

    $ perl -le 'print .36525872 * 24 * 60 * 60'
    31558.353408

    Then you can use gmtime to convert to a time.

    $ perl -MPOSIX -le 'print strftime ("%H:%M:%S", gmtime(.36525872*24*60*60))'
    08:45:58

    I'll bet some of the time modules will work in "excel time", but I
    haven't investigated to know which ones.

    --
    Darren Dunham
    Senior Technical Consultant TAOS http://www.taos.com/
    Got some Dr Pepper? San Francisco, CA bay area
    < This line left intentionally blank to confuse you. >
    Darren Dunham, Jul 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?ZGF2ZQ==?=

    Reading Excel sheet from asp.net returns empty cell

    =?Utf-8?B?ZGF2ZQ==?=, Feb 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    5,454
    venkatu2005
    Sep 5, 2009
  2. zxo102
    Replies:
    3
    Views:
    3,257
    Stuart Corrie
    Aug 9, 2005
  3. sajithkahawatta

    read a excel sheet using aspose.excel

    sajithkahawatta, Apr 19, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    543
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 19, 2007
  4. sagar

    Reading From an Excel Sheet

    sagar, Apr 30, 2007, in forum: Python
    Replies:
    2
    Views:
    250
    Dave Borne
    Apr 30, 2007
  5. sagar
    Replies:
    3
    Views:
    300
Loading...

Share This Page