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
相关推荐
泡海椒6 分钟前
JQuick-Excel 实战:用 STYLE 配置单元格与区域样式威联通网络存储12 分钟前
TS-h1283XU-RP 在医药批记录与检验场景的部署Patrick在香港21 分钟前
时间戳凭空早了 8 小时:datetime.utcnow() 弃用实测与漂移复盘东莞市云毅网络有限公司7 小时前
AI 引用句逐条回指原文:让回答可回溯的校验实现Sarvartha8 小时前
final 关键字数字融合9 小时前
透明化视频三维矿山井下照明重建技术yi0119 小时前
LeetCode 219:存在重复元素 II——哈希表记录“最近一次出现的位置”程序员Sunday9 小时前
JavaScript 事件循环面试题,宏任务与微任务怎么执行|Sunday面试指南zhangzeyuaaa10 小时前
Ruby 多线程、GVL(GIL)与 Mutex 完全指南Marst Code10 小时前
上位机开发日记 · 第 2 篇 · 架构先行:六层分层与边界