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
相关推荐
小北方城市网4 分钟前
第 8 课:Python 面向对象进阶 —— 类方法、静态方法与高级特性belldeep25 分钟前
python:markdown + python-docx 将 Markdown 文件格式转为 Word 文档CDwenhuohuo38 分钟前
uniapp去掉手机状态栏 全屏展示小钻风336643 分钟前
软件测试: 从入门到实践(接口自动化)别多香了1 小时前
Python 基础--循环判断&字符串老歌老听老掉牙1 小时前
使用 Matplotlib 自定义坐标轴字体及刻度样式详解早点睡觉好了1 小时前
JAVA中基本类型和包装类型的区别码农水水1 小时前
国家电网Java面试被问:二叉树的前序、中序、后序遍历Respect@1 小时前
qml之TableViewColumn股朋公式网2 小时前
斩仙飞刀、 通达信飞刀 源码