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
相关推荐
xlq223224 小时前
10.string(上)合作小小程序员小小店4 小时前
舆情,情感微博系统demo,基于python+qt+nlp,开发语言python,界面库qt,无数据库版,数据来自第三方网站获取,烟锁池塘柳04 小时前
【已解决】解决CondaVerificationError:PyTorch安装包损坏问题hashiqimiya4 小时前
c++的头文件使用panamera124 小时前
C++中vector拳里剑气4 小时前
C++:string的使用程序员爱钓鱼4 小时前
Python编程实战 | 函数与模块化编程 - 第三方库的安装与管理(pip使用)国服第二切图仔4 小时前
Rust开发之Result枚举与?运算符简化错误传播程序员爱钓鱼4 小时前
Python编程实战 | 面向对象与进阶语法-类与对象的概念Dovis(誓平步青云)5 小时前
《静态库与动态库:从编译原理到实战调用,一篇文章讲透》