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
相关推荐
凯瑟琳.奥古斯特5 分钟前
力扣1016高效解法:剪枝优化技巧databook38 分钟前
时间序列数据中,如何找出缺失值坤坤子吖1 小时前
C++继承:友元、静态成员、多继承与组合技术小甜甜1 小时前
【Cursor】Skill 被标黄色警告,怎么改成合格的 SKILL.md小小龙学IT2 小时前
Python Polars 高性能数据处理引擎深度解析csdn_aspnet2 小时前
JavaScript 未排序数组中第 k 个最小/最大元素 (预期线性时间)quantdash_cc2 小时前
如何利用标的信息为研究股票池补充名称和交易所信息?数字化转型分享点滴2 小时前
机加工企业上大数据分析系统有哪些容易踩的坑?B2_Proxy2 小时前
Scrapy 代理 IP 调度进阶:基于 Redis 与中间件的高可用架构实战在世修行2 小时前
智学文枢:AI 客户端封装