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
相关推荐
吴梓穆14 分钟前
Python 基础 正则表达式巧克力男孩dd30 分钟前
Python超典型练习题(第一次作业)TlSfoward37 分钟前
TLSFOWARD TLS指纹闲猫1 小时前
LangChain / Core components / Models-银雾鸢尾-3 小时前
C#中的索引器Qlittleboy3 小时前
PHP的接口参数传递的过多,max_input_vars = 5000Aurorar0rua3 小时前
CS50 x 2024 Notes Algorithms - 02en.en..3 小时前
冒泡排序与选择排序完整对比解析兰令水3 小时前
hot100【acm版】【2026.7.18打卡-java版本】cui_ruicheng4 小时前
Python从入门到实战(十三):模块、包与环境管理