def readfiletoexcel():
wb = xlwt.Workbook()
sheet = wb.add_sheet('端口信息')
#['Interface', 'PHY', 'Protocol', 'InUti', 'OutUti', 'inErrors', 'outErrors']
sheet.write(0,0,'Interface')
sheet.write(0,1,'PHY')
sheet.write(0,2,'Protocol')
sheet.write(0,3,'InUti')
sheet.write(0,4,'OutUti')
sheet.write(0,5,'inErrors')
sheet.write(0,6,'outErrors')
f = open("interface.txt", "r", encoding='utf-8')
lines = f.readlines()
result = "".join(lines)
res = result.split("\n")
j=0
for i in range(0,len(res)):
if len(re.findall(r'Interface',res[i]))>0:
j = i
regex = re.compile(r'GE.+\s+.+\s+.+\s+.+\s+.+\s+.+\s+.+',re.S)
if len(re.findall(regex, res[i])) > 0:
str = re.split('\s+',res[i])
print(str)
sheet.write(i-j,0,str[0])
sheet.write(i-j,1,str[1])
sheet.write(i-j,2,str[2])
sheet.write(i-j,3,str[3])
sheet.write(i-j,4,str[4])
sheet.write(i-j,5,str[5])
sheet.write(i-j,6,str[6])
wb.save("result.xls")
readfiletoexcel()
python往excel中写端口信息
Guaiacum_2024-10-12 23:13
相关推荐
IT召唤狮4 分钟前
开源企业级零信任项目Pangolin,零信任能挡住PHP核弹漏洞吗?知已难寻5 分钟前
03 · OpenStack的计算管理 NovaRover Ramble8 分钟前
C++ 用互斥锁实现读写锁薛定谔的猫-菜鸟程序员40 分钟前
软件架构设计师开发资料大全(从入门到精通)码流子1 小时前
移动收费怎么做?手持终端+App+收费中心的架构实践雪落漂泊1 小时前
C++算法 滑动窗口篇(下)云创智城-yuncitys1 小时前
YunParking 4.0:JDK 17 与 Spring Boot 3.2 的停车云升级郭小李2 小时前
openFeign入门wljt2 小时前
公司二-面试题Ramble_Naylor2 小时前
Rust深度解读:Send 与 Sync 的本质与线程安全边界