python往excel中写端口信息

复制代码
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()
相关推荐
KiefaC2 分钟前
【C++】红黑树的调整
开发语言·c++·算法
第二只羽毛2 分钟前
C++高性能内存池
开发语言·c++·缓存·性能优化
NullPointer83 分钟前
第21章:音频添加服务
python·aigc
ULTRA??4 分钟前
动态内存管理:C语言malloc极简封装方案(修正版,可申请二维数组)
c语言·开发语言
梁正雄6 分钟前
9、Python面向对象编程-1
服务器·开发语言·python
say_fall7 分钟前
C++ 入门第一课:命名空间、IO 流、缺省参数与函数重载全解析
c语言·开发语言·c++
霸王大陆13 分钟前
《零基础学 PHP:从入门到实战》模块十一:成为 PHP 侦探,精通错误处理与调试实战大全-1
开发语言·笔记·php·课程设计
郝学胜-神的一滴15 分钟前
Python的内置类型:深入理解与使用指南
开发语言·python·程序人生
松☆18 分钟前
C语言--结构体
c语言·开发语言
关于不上作者榜就原神启动那件事22 分钟前
【java后端开发问题合集】
java·开发语言