Being a lazy networking guy - Accessing Excel data from Python
Following tools required in windows : (if you are a Linux guy most probably not reading this :) )
- you can find the python windows executable in following URL : Python download link
- I'm using notepad++ with PyNPP , you can install this from plugin manager. you need to edit the python location in PyNPP option.
- Installing openpyxl is quite easy on Windows, you can find pip at C:\Python34\Scripts\pip.exe just run following command to install openpyxl "C:\Python34\Scripts> pip install openpyxl "
import openpyxl wb = openpyxl.load_workbook('test.xlsx') sheets = wb.get_sheet_names() #print (sheets) sheet = wb.get_sheet_by_name("Sheet2") for i in range (1,16): print ("interface ",sheet.cell(row=i,column=2).value,"\n description *** Link to ",sheet.cell(row=i,column=4).value,"-",sheet.cell(row=i,column=5).value," ***")This is the input data i had
Input - Data |
Following is the output created by the script
['Sheet1', 'Sheet2', 'Sheet3', 'Sheet4'] interface Port Number description *** Link to Remote Device - Remote Port *** interface Eth1/1 description *** Link to ABC_7710_CORE2 - Eth1/1 *** interface Eth1/2 description *** Link to ABC_7710_CORE2 - Eth1/2 *** interface Eth1/3 description *** Link to N/A - N/A *** interface Eth1/4 description *** Link to N/A - N/A *** interface Eth1/5 description *** Link to LOC1_7710_DIST1 - Eth1/1 *** interface Eth1/6 description *** Link to LOC1_7710_DIST2 - Eth1/1 *** interface Eth1/7 description *** Link to LOC2_7710_DIST1 - Eth1/1 *** interface Eth1/8 description *** Link to LOC2_7710_DIST2 - Eth1/1 *** interface Eth1/9 description *** Link to LOC3_7710_DIST1 - Eth1/1 *** interface Eth1/10 description *** Link to LOC3_7710_DIST2 - Eth1/1 *** interface Eth1/11 description *** Link to LOC4_7710_DIST1 - Eth1/1 *** interface Eth1/12 description *** Link to LOC4_7710_DIST2 - Eth1/1 *** interface Eth1/13 description *** Link to ABC_7710_SFDIST1 - Eth1/1 *** interface Eth1/14 description *** Link to ABC_7710_SFDIST2 - Eth1/1 ***References :
- https://www.python.org/downloads/
- https://automatetheboringstuff.com/chapter12/
- https://openpyxl.readthedocs.org/en/default/
- https://notepad-plus-plus.org/
- http://www.pythonlearn.com/book.php
Comments