1
我是Python新手。我想從多個XML文件中檢索標籤值並將其打印在Excel表格中。我試過,並得到了除了Excel打印部分以外的腳本工作正常。在Excel中打印輸出
這是我的腳本
from xml.dom.minidom import parse, parseString
import xlwt
import os
def sh(dir):
for r,d,f in os.walk(dir):
n=0
for files in f:
if files.endswith(".xml"):
print files
dom=parse(os.path.join(r, files))
name = dom.getElementsByTagName('rev')
title = dom.getElementsByTagName('title')
a=xlwt.Workbook()
sheet=a.add_sheet('sheet1')
sheet.write(n, 0, files)
sheet.write(n, 1, title[0].firstChild.nodeValue)
sheet.write(n, 2, name[0].firstChild.nodeValue)
n=n+1
a.save('sha.xls')
print title[0].firstChild.nodeValue
print name[0].firstChild.nodeValue
sh("path")
我卡住了,則輸出僅在這些列中打印的問題(0,0),(0,1),(0,2)。
例如如果我想
A B C
D E F
G H I
我的輸出
G H I
在
(0,0),(0,1),(0,2)。 所以我明白,現有的每一個新的輸出都被覆蓋,只顯示最終的輸出。我怎樣才能避免這一點,並得到我想要的?
非常感謝。它確實工作正常。我不知道glob.glob()格式,會嘗試使用這個。再次感謝..:) –