使用Python将如下xml格式转换为Excel格式:

xml转为xls格式文件:

xml格式如下:

<?xml version="1.0" encoding="UTF-8"?>
<photos>
<photo src="assets/images/001/3.jpg" desc="把兰花种进去!"/>
<photo src="assets/images/002/1.jpg" desc="每天都要锻炼身体哦!"/>
<photo src="assets/images/001/1.jpg" desc="我们在种兰花!"/>
<photo src="assets/images/001/2.jpg" desc="先把泥巴挖开!"/>
</photos>

通过使用lxml模块创建xml文件,使用xlwt模块创建Excel文件,转换方法如下

#coding:utf-8
#xml与Excel相互转换
from lxml import etree
import xlwt as xlwt wb=xlwt.Workbook()
ws=wb.add_sheet("employee") tree=etree.parse("employee2.xml")
root=tree.getroot() row=0
col=0 for item in root:
if len(item.attrib)==0:
continue row=row+1
col=0 for attr in item.attrib:
print attr
ws.write(row,col,item.attrib[attr])
col=col+1 wb.save("test.xls")

最后结果如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAf8AAACICAIAAABmw3UkAAAQdUlEQVR4nO2dMY7bOhCG9Q60xWK7PUSAtD6AuyAn8AGCIMBewF2KNGndKd22KZ8LI0d4F0ijV+xaIjnD4VCy7Bn6/yAEWpmiqA35kUtLnO4VAADA/dH9XYHX19d//8OGzcr2+vq6Rj0HwHXVgv2xtb+5bqLAMq6rFuyPrf3NdRMFlnFdtWB/o1v/6+Hx68OXP7cvSQOb6yZ6DU77zVPCrr91oVywYtWK/lNW+e+A/W1uP77sHz79fPj468etS9LCBvsXOO03T5v9KT6ADkDBWlWr3z0F/yMr/XfA/ia33x8e95/73x8ev374fvPC+N9g/wLE/n9P+w3sr2CdqtXvUtnT/6ELAPtb3L7/7D7++vHvf98+fe0+/b59ebxvsH8Bbux/cdc0ySpV61pdL+xvcPv26Tzj3/96ePz57dblcb/B/gWYef/LjzSbZJWq1e+u89uH/c1tkfH/fP6I734Xb7B/ATqvQOceAAfsnwL7L9h+fNl3j1//CTd897twg/0LMLPK1zKQczDzkwL7z9/+fP4Yf9Pb/3p43H/ub14wzxvsXw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WvsLO8K+UBhll1P8EVwH2L9h+zsNhDIKHdFdhkF84jM8GA6TkyFz+tdWScS5ZDlqL1rsG8B1gP0btv/gLhAKortQXDdRYBnXVQvRXQAA4B7B2B+0z9HzAA1YxnXVgv1B+7huosAyrqsW7A/ax3UTBZZxXbU09p+e+Fcu8gn7A1O4bqLAMq6rliq6y7v1g/U+YX/gCNdNFFjGddVSre9vLLoLAHW4bqLAMq6rlmZ9/9rAjrA/sIXrJgos47pqKVZ52+z788S/sh+A/YEpXDdRYBnXVUuzxmcY3Avz/sAfrpsosIzrqlWxwvPc6C4A3BjXTRRYxnXVqpr3h/2BS1w3UWAZ11VL9cTn+3SPNqwv7A9s4bqJAsu4rlp1b3vhW1/gEddNFFjGddXCSg+gfVw3UWAZ11UL9gft47qJAsu4rlqwP2gf100UWMZ11UJ0FwAAuEcw9gftc/Q8QAOWcV21YH/QPq6bKLCM66oF+4P2cd1EgWVcVy3VOj8Rimf+YX9gCtdNFFjGddWqGftjlTfgE9dNFFjGddXS21/tftgfGMN1EwWWcV211PZXL/ID+wNruG6iwDKuq5bS/hUDf9gfWMN1EwWWcV21dPavkz/sD2zhuokCy7iuWjr7V4Z2h/2BKVw3UWAZ11VLZf+aOX/YH5jDdRMFlnFdtbTr+9fIH/YHtnDdRIFlXFctjf1rh/6wP7CF6yYKLOO6amGlB9A+rpsosIzrqgX7g/Zx3USBZVxXLdgftI/rJgos47pq/Q/gZHp1SKQvOAAAAABJRU5ErkJggg==" alt="" />

xls格式文件转换为xml:

xls格式文件如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkEAAABoCAIAAAB5WrMtAAAMzklEQVR4nO2dPY7bvBaGfRc0xcCdFxEgrRfgLsgKvIAgCOANuEuRJq2bC003bcpvCiE7+ILbp9EtZizx50iiZNPD13oesPDQln3kOdRrUiTf1b9//kehUCgUimJZPQMAAGiy+puH5+fnf/5QKKWU5+fnTKkOC0c9tdTjR8MoiyjqDRWKRT211ONHwyiLKOoNFYp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GBROGBORv1hgrFop5a6vEnaNibgl1jTgcemBdpGB6Y8wkaqrk7olkJMIy6BqjHP65h1X668woemNfwwDwf4r758MaH4RPWnr94YLJvPVwTdQ1Qj39Uw6r9OiLBgAUPzAs9MJ3gDTW0XxA9YWkY/TBbotAtmIe6BqjHn399mG0sadhF4oFpqLnz2fY8Szww00DDIBPqGqAe/w3WOOOB6X7hE9c4d1KDB+ZFMJYImVDXAPX42WtqKirDbnhgevTN6RitBBhGXQPU40fDRhG1i2xlCQ/MptFvqFAs6qmlHj8aloI7C7GQvT+GwAMzRr2hQrGop5Z6/HhgAgCAKvTDYBG8iP/YhGJRTy31+NEwWATqDRWKRT211ONHw2ARqDdUKBb11FKPP3XP32m7dJShYXfugdktZsMDcxz1hgrFop5a6vEnaVi3ZWIyBfiHFW0gFuzTMd0D095iH/pQb6hQLOqppR5/ioa1G9draVjJEnaxB6b3Bdz/CuXLMRuquaKZZc4wCXUNUI8/RcPeLJzX6/UaD8xiPDAdTA3DA9Ojr6GacoWGQTrqGqAef5p/2Fm66uN2+v0wc9QLD8wZ3iv2nomnnXlHDA9MDzQMMqGuAerxT52XWO3TRAwPzMFImlkaZkiYK8s9J4AHZtPggQnZUNcA9finalh93M7QMDwwo8+Zo2HhSGK/gDWBhgXDnXhgxo/NSoBR1DVAPf4Z/bCkW2J4YOb2wBwUsKZfw+iHoWFwTdQ1QD3+BA1zhg+rfeqsDjww83pgjm81jwemBxoGmVDXAPX4p65xTl0nhgdmVg/MYCjzfCQemL2gYZAJdQ1Qj5+9pqaiMuyGB6bHwJwOV8biSoBh1DVAPX40bBRRu8hWlvDAbBr9hgrFop5a6vGjYSm4Q3eF7P0xBB6YMeoNFYpFPbXU48cDEwAAVPk/FZGG5Fa+784AAAAASUVORK5CYII=" alt="" />

xls转换为xml:

#coding:utf-8
from lxml import etree
import xlrd,codecs def getPathFileName(path):
tmp=path.split('/')
return tmp[len(tmp)-1].split('.')[0] def xlsToxmlPath(path):
return path.split('.')[0]+'.xml' def export(path):
data=xlrd.open_workbook(path,formatting_info=True)
table=data.sheets()[0] f=open(xlsToxmlPath(path),'wb')
f.write(u'<?xml version="1.0" encoding="utf-8" ?>\n')
f.write(u'<%s>\n'% getPathFileName(path)) for i in range(1,table.nrows):
s=u'<item';
tmp = [u' %s = "%s"' % (str(table.cell_value(0,j)), str(table.cell_value(i,j))) for j in range(table.ncols)]; s+=u' '.join(map(str,tmp));
s+=u'>\n';
f.write(s); f.write(u'</%s>'%getPathFileName(path)); export('test.xls')

结果为:

<?xml version="1.0"  encoding="utf-8" ?>
<test>
<item src = "assets/images/001/3.jpg" content = "aa">
<item src = "assets/images/002/1.jpg" content = "bb">
<item src = "assets/images/001/1.jpg" content = "cc">
<item src = "assets/images/001/2.jpg" content = "dd">
</test>

xml与Excel转换的更多相关文章

  1. TestLink学习七:TestLink测试用例Excel转换XML工具

    TestLink对于测试用例的管理来说,是蛮强大的,但是在导入导出这块,功能有点弱,本文针对测试用例的导入,转载了一个Excel转换成xml工具. 1.根据到处的测试用例xml,定义一下我的Excel ...

  2. 转:TestLink1.9.3测试用例:Excel转换XML工具<二>实现代码

    TestLink1.9.3测试用例:Excel转换XML工具<二>实现代码 http://blog.csdn.net/candle806/article/details/7490599 以 ...

  3. 转:Excel转换XML工具<一>

    http://blog.csdn.net/candle806/article/details/7441695最近在整理测试用例,所以想找一个合适的工具来完成对测试需求.测试用例的管理.对比了一翻,发现 ...

  4. 【Python】Xml To Excel

    [Python3] 之前做的入门练习里有一题将excel文件转化为xml文件,这回补上逆向转换→xml to excel 用的还是beautifulsoup. 主要还是:①读取待处理文件文本内容 ②处 ...

  5. Open XML操作Excel导入数据

    项目中发现使用OleDb(using System.Data.OleDb)相关对象处理Excel导入功能,不是很稳定经常出问题,需要把这个问题解决掉.项目组提出使用OpenXML来处理Excel的导入 ...

  6. 使用Open xml 操作Excel系列之一-读取Excel

    一. 安装Open Xml SDK 从微软网站下载Open xml SDK,安装SDK. 二. 在项目中添加对DocumentFormat.OpenXml库的引用

  7. 使用JAXB来实现Java合xml之间的转换

    使用jaxb操作Java与xml之间的转换非常简单,看个例子就明白了. //javaBean-->xml @Test public void test1() { try { JAXBContex ...

  8. java与xml之间的转换(jaxb)

    使用java提供的JAXB来实现java到xml之间的转换,先创建两个持久化的类(Student和Classroom): Classroom: package com.model; public cl ...

  9. Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类

    Java 通过Xml导出Excel文件,Java Excel 导出工具类,Java导出Excel工具类 ============================== ©Copyright 蕃薯耀 20 ...

随机推荐

  1. [剑指Offer]36-二叉搜索树与双向链表

    链接 https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5?tpId=13&tqId=11179&tPa ...

  2. (转载)Android开发——Android中常见的4种线程池(保证你能看懂并理解)

    0.前言 转载请注明出处:http://blog.csdn.net/seu_calvin/article/details/52415337 使用线程池可以给我们带来很多好处,首先通过线程池中线程的重用 ...

  3. 获取当前最顶层的ViewController

    - (UIViewController *)topViewController { UIViewController *resultVC; resultVC = [self _topViewContr ...

  4. 20172325 2018-2019-2 《Java程序设计》第七周学习总结

    20172325 2018-2019-2 <Java程序设计>第七周学习总结 教材学习内容总结 二叉查找树 二叉查找树:是含附加属性的二叉树,即其左孩子小于父节点,而父节点又小于或等于右孩 ...

  5. 全渠道java b2b b2c o2o平台

    大型企业分布式互联网电子商务平台,推出PC+微信+APP+云服务的云商平台系统,其中包括B2B.B2C.C2C.O2O.新零售.直播电商等子平台. 根据微服务化设计思想,结合spring cloud一 ...

  6. 大型互联网 b2b b2c o2o 电子商务微服务云平台

    鸿鹄云商大型企业分布式互联网电子商务平台,推出PC+微信+APP+云服务的云商平台系统,其中包括B2B.B2C.C2C.O2O.新零售.直播电商等子平台. 分布式.微服务.云架构电子商务平台 java ...

  7. 设置DataGridView中表头颜色

    默认的DataGridView表头颜色实在不是太好看,想设置下,上google搜了一通, 都说这样设置 this.dataGridView1.ColumnHeadersDefaultCellStyle ...

  8. linux 查看信息-系统&资源

    系统 1.查看内核/操作系统/CPU信息 2.查看操作系统版本 3.查看CPU信息 4.查看计算机名 5.列出所有PCI设备 6.列出所有的USB设备 7.列出加载的内核模块 8.查看环境变量 资源 ...

  9. hadoop启动

    安装完hadoop集群之后,第一次启动之前必须初始化,之后就可以不用再初始化(注意:初始化操作只可以一次) hdfs namenode -format (hadoop namenode -format ...

  10. 第35章:MongoDB-集群--Master Slave(主从复制)

    ①主从复制 最基本的设置方式就是建立一个主节点和一个或多个从节点,每个从节点要知道主节点的地址.采用双机备份后主节点挂掉了后从节点可以接替主机继续服务,所以这种模式比单节点的高可用性要好很多. ②注意 ...