我在使用 openpyxl 创建脚本时遇到问题 - 简而言之,该脚本的目的是读取 excel 表格单元格值并为 Juniper CLI 打印 CLI 命令。
我的问题是我想自动化脚本查找特定行“规则名称”并在之后打印以下列(即源地址/目标地址)的过程
正如您从下面的脚本中看到的那样,我当前的工作是手动输入行号,但如果我可以通过检测特定的约定名称(例如“StackOverflow 1,StackOverflow 2”)并为规则 2 打印另一组命令来自动化它,那就是太棒了,我只是不确定该怎么做。
有没有人可以帮忙。
import openpyxl
from openpyxl import load_workbook
wb = load_workbook(input('Workbook name: '), data_only=True)
ws = wb["Sheet name"]
rownumber = int(input('Row Number Of Rule: '))
name = (ws.cell(row=rownumber, column=1).value)
source = (ws.cell(row=rownumber, column=4).value)
destination = (ws.cell(row=rownumber, column=5).value)
port = (ws.cell(row=rownumber, column=6).value)
description = (ws.cell(row=rownumber, column=10).value)
fromzone = (ws.cell(row=rownumber, column=2).value)
tozone = (ws.cell(row=rownumber, column=3).value)
print ('set logical-systems security policies from-zone %s to-zone %s policy %s match source-address %s' %(fromzone,tozone,name,source))
print ('set logical-systems security policies from-zone %s to-zone %s policy %s match destination-address %s' %(fromzone,tozone,name,destination))
print ('set logical-systems security policies from-zone %s to-zone %s policy %s match application %s' %(fromzone,tozone,name,port))
print ('set logical-systems security policies from-zone %s to-zone %s policy %s description %s' %(fromzone,tozone,name,description))
print ('set logical-systems security policies from-zone %s to-zone %s policy %s then permit' %(fromzone,tozone,name))
print ('set logical-systems security policies from-zone %s to-zone %s policy %s then log session-init' %(fromzone,tozone,name))