Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Time duration using Excel::Writer::XLSX

by dr.jekyllandme (Sexton)
on Dec 05, 2012 at 23:44 UTC ( #1007428=perlquestion: print w/replies, xml ) Need Help??
dr.jekyllandme has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to write a column on duration( hh:mm:ss ) to an excel file. My only problem is figuring out what format I should use. I am using the Excel::Writer::XLSX module. When I did a quick web search, I found that the correct way to define a duration is to use []( ). This works correctly when I do this in excel. But I need to use Perl to generate my spreadsheet because I have lots of data. This is a snippet of my code:
my $workbook = Excel::Writer::XLSX->new( 'build_results.xlsx' ); my $worksheet = $workbook->add_worksheet(); my $format = $workbook->add_format( num_format => '[hh]:mm:ss' ); $worksheet->write_date_time( "A$col", '12:20:12', $format ); # i n +eed this to be considered 12 hours 20 mins and 12 secs.
I am new to Excel::Writer::XLSX and I am not even sure If I should be using write_date_time. If anyone can enlighten me, it would be greatly appreciated. Thanks.

Replies are listed 'Best First'.
Re: Time duration using Excel::Writer::XLSX
by Anonymous Monk on Dec 06, 2012 at 01:08 UTC


    According to the docs, you need to put 'T' in front os the time string you are sending to the sub. 'T12:20:12' rather than '12:20:12'.


Re: Time duration using Excel::Writer::XLSX
by rpnoble419 (Pilgrim) on Dec 07, 2012 at 01:09 UTC

    I create reports using this module all the time. I create a text format for the date and time if you are not going to use it in a formula. This forces excel to display as I want the date and time not as Excel wants when the use has set the local date and time format on their computer. The code below is from my database while loop..

    $worksheet1->write_string($row, $col++,$data->{$dataElement});

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007428]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-09-23 12:38 GMT
Find Nodes?
    Voting Booth?
    Eventually, "covfefe" will come to mean:

    Results (191 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!