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
相关推荐
nice_lcj5201 小时前
Java Lambda 表达式入门:怎么写、怎么用、常用方法有哪些维克兜率天1 小时前
【维克】复合型CTA:趋势+套利的双轮驱动伞伞悦读1 小时前
【第76期】两张3行表左连接变5行:主键、validate与未匹配排查完整教程码农小河661 小时前
基于SSM+JSP+MySQL的在线医疗服务系统的设计与实现用户8356290780512 小时前
使用 Python 在 Excel 中添加和自定义迷你图用户8356290780512 小时前
使用 Python 在 Excel 图表中添加趋势线与回归方程特立独行的猫A3 小时前
一份 Markdown 发十个平台:cspub 一稿多投深蓝AI3 小时前
HTTPX 超时 1 秒,接口为何还能跑 2.4 秒?CyrusYiVPP3 小时前
哪个用户会再来买?RFM模型+plotly画出用户分层,数据分析实战第2期李帅5155 小时前
用 CPU 做发票识别:从 OCR 文本行到结构化明细表的 4 个硬骨头