2017-10-12 73 views
0

我正在使用Excel工作表进行迁移准备。我有一个工作簿/工作表,其中包含Netscalers(MAS)上存在的所有网络服务器IP。我需要获取Migration_prep工作簿/工作表中列出的一列IP,并通过MAS表中的IP进行循环,并进行任何匹配并将它们放入另一个工作簿中。 我可以使用文本文件做到这些,但我希望只保留所有数据在Excel表格中。我已经阅读了“使用Python自动化枯燥的东西”一书,但它并没有教会如何做到这一点。我已经搜索谷歌和这里的答案,但没有甚至接近。Python脚本需要一列IP,在另一个工作簿中搜索匹配的匹配项,将匹配项放在另一个工作簿中。

import openpyxl 
import xlrd 
import xlwt 


wb1 = openpyxl.load_workbook('LB_migration.xlsx') 
ws1 = wb1.get_sheet_by_name('Servers') 
#IP should be placed in Column 'J2' and continue down for as much as needd. 

wb2 = openpyxl.load_workbook('ME06.xlsx') 
ws2 = wb2.get_sheet_by_name('Dependency_Details') 
#Migration server IPs are listed in Column P starting with row 2. 

wb3 = openpyxl.load_workbook('MAS.xlsx') 
ws3 = wb3.get_sheet_by_name('massheet') 
#All servers listed in Netscaler configs are in column C starting in row 2 
#This should be the list that is parsed with the Migration server IPs 

ws1.iter_rows('A1:A235') 
+1

如果你阅读循环和openpyxl的章节,你会发现它实际上给你提供了你需要的一切。 – toonarmycaptain

+1

我通过两遍阅读该章节,然后走出了Python循环课程,获取了Python Crash Course。谢谢 –

+1

请提供一个比较和改变的例子。 –

回答

1

您可以使用像这样把数据转换为Python列表中每一列要比较:

mylist = [] for col in ws1.columns[0]: mylist.append(col.value)

在读取数据后,你可以只使用更多的循环可以通过比较找到你想要的数据。

+0

我打算写一个不同的答案,但我认为这涵盖了它。使用循环和'iter_rows()'函数,你应该能够得到你想要的。 – NoOrangeJuice

相关问题