R1 Y1 D1 L1 R2 Y2 D2 L2 R3 Y3 D3 L3 R4 Y4 D4 L4
import xml.etree.ElementTree as ETimport xlsxwritertree = ET.parse('20190607.xml')root = tree.getroot()#print(root.tag)# 一个节点有tag、attrib、text三个值# tag是标签的名字# text是标签的内容# attrib是标签属性的字典,通过字典的get('key')来获取对应的属性的值workbook = xlsxwriter.Workbook('excle20190607.xlsx') # 创建一个Excel文件title = ['RQ','YBZMC','DCQMC','LTCSZQDM'] #表格titlerow = 1# 直接for chile in parent 来遍历节点下的子节点print('总条数:',len(root))worksheet = 0for index, child in enumerate(root): #print(child.tag, child.attrib) if index % 60000 == 0: #每60000条数据分一个sheet worksheet = workbook.add_worksheet() worksheet.write_row('A1', title) row = 1 for elem in child: #print(elem.tag, elem.text) worksheet.write(row, title.index(elem.tag), elem.text) row += 1workbook.close()