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()
相关推荐
景彡先生4 小时前
Python Selenium详解:从入门到实战,Web自动化的“瑞士军刀”
前端·python·selenium
程序员卷卷狗4 小时前
JVM 调优实战:从线上问题复盘到精细化内存治理
java·开发语言·jvm
lly2024065 小时前
ASP Folder:深入解析其功能与使用技巧
开发语言
雪域迷影5 小时前
Go语言中通过get请求获取api.open-meteo.com网站的天气数据
开发语言·后端·http·golang·get
珺毅同学6 小时前
YOLO输出COCO指标及YOLOv12报错
python·深度学习·yolo
ysdysyn7 小时前
C# 进程管理实战:检查与启动EXE程序的完整指南
开发语言·c#
IDOlaoluo7 小时前
PHP-5.2.1.tar.gz 离线安装教程:从源码编译到配置的详细步骤(附安装包)
开发语言·php
2401_841495648 小时前
Windows 系统中ffmpeg安装问题的彻底解决
windows·python·ffmpeg·bug·语音识别·下载·安装步骤
wangjialelele8 小时前
Qt中的常用组件:QWidget篇
开发语言·前端·c++·qt
waysolong908 小时前
MCP服务构建、使用
python