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()
相关推荐
Humbunklung6 分钟前
Rust Floem UI 框架使用简介
开发语言·ui·rust
Yxh1813778455441 分钟前
抖去推--短视频矩阵系统源码开发
人工智能·python·矩阵
网安INF43 分钟前
RSA加密算法:非对称密码学的基石
java·开发语言·密码学
明月*清风44 分钟前
c++ —— 内存管理
开发语言·c++
蔡蓝1 小时前
设计模式-观察着模式
java·开发语言·设计模式
Humbunklung1 小时前
PySide6 GUI 学习笔记——常用类及控件使用方法(多行文本控件QTextEdit)
笔记·python·学习·pyqt
火车叼位2 小时前
使用 uv 工具在 Windows 系统快速下载安装与切换 Python
python
西北大程序猿2 小时前
单例模式与锁(死锁)
linux·开发语言·c++·单例模式
你不是我我2 小时前
【Java开发日记】说一说 SpringBoot 中 CommandLineRunner
java·开发语言·spring boot
心扬2 小时前
python网络编程
开发语言·网络·python·tcp/ip