Chinaunix首页 | 论坛 | 博客
  • 博客访问: 109336
  • 博文数量: 49
  • 博客积分: 2612
  • 博客等级: 少校
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 14:31
个人简介

来来去去

文章分类

全部博文(49)

文章存档

2015年(1)

2012年(4)

2011年(1)

2010年(42)

2009年(1)

我的朋友

分类: Python/Ruby

2010-06-18 17:58:01

 

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# This script use to get the data from XML file and then put this data in a excel.


from xml.dom import minidom
from pyExcelerator import
import sys
import os
import datetime
import time


def getTagText(root,tag,current_time):
    Allnodes=root.getElementsByTagName(tag)
    w=Workbook()
    ws=w.add_sheet(current_time)
    row,col=1,1
    for nodes in Allnodes:
        for node in nodes.childNodes:
            if node.nodeType != node.TEXT_NODE:
                #print node
                #print node.childNodes[0].data
                s=node.childNodes[0].data
                ws.write(row,col,s)
                col+=1 #next col
        # Reset next row
        row+=1
        col=1
    w.save('F:\\python\\xmldata\\'+current_time+'.xls')


#Format the time as 'YYmmddHHMMSS'
def format_time():
    x=time.localtime()
    t=datetime.datetime(*x[:6])
    return t.strftime("%Y%m%d%H%M%S")

if __name__=='__main__':
    #path=sys.arv[1]
    path="F:\\Python\\test.xml"
    root=minidom.parse(path)
    tag='ExchangeRate'
    current_time=format_time()
    getTagText(root,tag,current_time)


阅读(752) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~