Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
writing to time format fields in Excel
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mike  
View profile  
 More options Oct 13, 6:47 am
From: Mike <mike.i.bradf...@gmail.com>
Date: Mon, 12 Oct 2009 13:47:15 -0700 (PDT)
Local: Tues, Oct 13 2009 6:47 am
Subject: writing to time format fields in Excel
Hi

just finished writing some code to generate reports by writing data
into an Excel spreadsheet using COM. (Unfortunately XLWT/XLRD etc
wasn't an option because the Excel spreadsheet included charts).

Since there are numerous examples for open, writing to, and saving
Excel files I won't go into that here :-)

One tidbit I found was that Excel time formatted data is stored as a
decimal value between 0.0 and 1.0 depending on how far through the day
it is.

Here is some example code for converting a time to Excel format,
suitable for writing into an Excel time formatted field.

def cnvrt_time(csv_time):
    # csv_time is time in format '00:10:22.634' = 'hh:mm:ss.xxx'
    # excel time format stores time as decimal
    secs_in_day = 24*60*60
    csv_time = csv_time.split('.')[0] # drop milliseconds
    [hrs,mins,secs] = csv_time.split(':')
    total_secs = float(secs)+60*float(mins)+3600*float(hrs)
    time_in_xcl_fmt = total_secs / secs_in_day
    return(time_in_xcl_fmt)

Hope it's useful to somebody else.

Mike


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Machin  
View profile  
 More options Oct 13, 8:50 am
From: John Machin <sjmac...@lexicon.net>
Date: Tue, 13 Oct 2009 09:50:04 +1100
Local: Tues, Oct 13 2009 8:50 am
Subject: Re: [pyxl] writing to time format fields in Excel
On 13/10/2009 7:47 AM, Mike wrote:

> Hi

Hi, Mike,

Welcome to the group.

> One tidbit I found was that Excel time formatted data is stored as a
> decimal value between 0.0 and 1.0 depending on how far through the day
> it is.

I presume that you mean "decimal" in the sense of a colloquial
abbreviation of "decimal fraction". Excel's time-of-day convention is in
fact (as your code implies) a *float* fraction of a day. Especially
given the existence of Python's "decimal" data type, calling it
"decimal" doesn't seem a good idea.

One possible source of such tdbits is the xlrd documentation ... e.g.
(1) the general rant about Excel dates at the front of the docs
(2) this convenience function:

xldate_from_time_tuple((hour, minute, second))

     Convert a time tuple (hour, minute, second) to an Excel "date"
value (fraction of a day).

> Here is some example code for converting a time to Excel format,
> suitable for writing into an Excel time formatted field.

> def cnvrt_time(csv_time):
>     # csv_time is time in format '00:10:22.634' = 'hh:mm:ss.xxx'
>     # excel time format stores time as decimal
>     secs_in_day = 24*60*60
>     csv_time = csv_time.split('.')[0] # drop milliseconds
>     [hrs,mins,secs] = csv_time.split(':')
>     total_secs = float(secs)+60*float(mins)+3600*float(hrs)
>     time_in_xcl_fmt = total_secs / secs_in_day
>     return(time_in_xcl_fmt)

> Hope it's useful to somebody else.

I'm sure it will be.

Cheers,
John


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google