文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Python Handle XML and Generate data into Excel

Python Handle XML and Generate data into Excel

时间:2010-06-18  来源:angelia_liu

 

#!/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)


相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载