首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python写入excel

Python写入excel
EN

Stack Overflow用户
提问于 2013-09-17 22:24:30
回答 1查看 116关注 0票数 0

我想要获得以下结构:

代码语言:javascript
复制
                 Day 1   |    2    |   3    | 4       ... Total
stackoverflow                04:00            01:00       05:00
google             05:30               02:00              07:30

但是通过我的代码,我得到了:

代码语言:javascript
复制
                 Day 1   |    2    |   3    | 4      ...  Total
stackoverflow                04:00                        04:00
google             05:30                                  05:30
stackoverflow                                01:00        01:00
google                               02:00                02:00

我运行了这个查询(它是given here):

代码语言:javascript
复制
select 
  agenc.name, 
  sum(cast(servic.end_hour as time) - cast(servic.begin_hour as time)) as time_, jobs.description
from 
  services as servic  
  join services_jobs AS jobs ON jobs.id = servic.job_id  
  join agency as agenc ON agenc.id = jobs.agency_id
where  
  extract(month from servic.service_date) = 9 and  
  extract(day from servic.service_date) = 16
group by
  agenc.name

在python中,我执行了相同的查询,不同之处在于查询"extract(day from servic.service_date)“中的”day column“等于循环(从1到31 -> day count)

代码语言:javascript
复制
query_A = cr.fetchall()
    if query_A:
        for values in query_A:
            sheet.write(line_, 0, values[0], style_main) # Writes the name
            sheet.write(line_, 1, values[2], style_main) # Writes the job

            current_value = str(values[1]);
            hours_ = current_value.split(':')[0]
            minutes_ = current_value.split(':')[1]
            total_ = hours_ +':'+ minutes_ # This will get 02:00 - for example

            sheet.write(line_, i + 1, total_, style_main) # write the result
            total_vertical += timedelta(hours=int(hours_), minutes=int(minutes_)) # here should sum the results along the days
            sheet.write(line_, 33, str(total_vertical), style_main) # write it on "total" column    
            line_ += 1

            total_vertical = timedelta(hours=0, minutes=0) # Reset 

有没有什么建议,我应该如何着手来获得我想要的结果?谢谢!

EN

回答 1

Stack Overflow用户

发布于 2013-09-18 01:06:11

问题已解决,请参阅以下链接中的代码:http://pastebin.com/kcH1bTMp

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18852541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档