0
我有兩個工作簿:比較值
- wkbk1具有在特定列的每個小區中的單個IP地址。
- wkbk2沒有IP地址,單個IP或多個IP, 在特定的 列的每個單元格中以新行(vs逗號)分隔。
我想比較wkbk1中的單元格的值與wkbk2中的值。
我遇到的問題是,搜索將比較wkbk1 IP = 10.10.10.16等於wkbk2 IP = 10.10.10.168(和任何其他變體)。
如果我通過(wkbk1 IP + \ n)進行搜索,它無法比較單行單元格。
以下是我的代碼:
#variable top store the highest row number
mRow = str(mapIP.get_highest_row())
eRow = str(assetSheet.get_highest_row())
i = 2 #variable for row number output, skips the first row (b/c it is the header row, duh)
#create data by comparing IP in map to IP in CMDB
for mapIpRow in mapIP['A1':'A' + mRow]:
for mapIpCell in mapIpRow:
for assetIpRow in assetSheet['E1':'E' + eRow]:
for assetIpCell in assetIpRow:
assetIp = str(assetIpCell.value)
mapIp = str(mapIpCell.value)
if mapIp in assetIp:
outSheet['A' + str(i)].value = mapIp
print(mapIp) #just for feedback that the program is running
dnsM = mapIP['B' + str(mapIpCell.row)].value
owner = assetSheet['F' + str(assetIpCell.row)].value
dnsQ = assetSheet['B' + str(assetIpCell.row)].value #cishort
dnsQ2 = assetSheet['C' + str(assetIpCell.row)].value #cialias
dnsQ3 = assetSheet['D' + str(assetIpCell.row)].value #ciDesc
ciIP = assetSheet['E' + str(assetIpCell.row)].value #ciIP
ciID = assetSheet['A' + str(assetIpCell.row)].value #ciID
outSheet['B' + str(i)].value = dnsM
outSheet['C' + str(i)].value = owner
outSheet['D' + str(i)].value = dnsQ
outSheet['E' + str(i)].value = dnsQ2
outSheet['F' + str(i)].value = dnsQ3
outSheet['G' + str(i)].value = ciIP
outSheet['H' + str(i)].value = ciID
print owner #just for feedback that the program is running
i = i + 1
else:
pass
這工作完美!我不得不將assetIpCell.value轉換爲一個字符串,然後分割成一個列表。非常感謝! – MACanazon
乾杯。如果解決了問題,請考慮將此答案標記爲「已接受」。出於好奇,「assetIpCell.value」中的數據類型是以什麼開頭的?我希望它是字符串(但我沒有測試) –
它是一個IP地址的單元格,它們由回車而不是逗號分隔。但是有些單元格是空的,他們將被分配一個Nonetype – MACanazon