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