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
相关推荐
MOONICK1 小时前
QT元数据卷无止境1 小时前
RAGFlow 项目全景报告:从文档解析引擎到 Agent 原生数据库D e re k ZH2 小时前
C++ 系统学习手记:从语法细节到工程实践灿飞屋2 小时前
Kotlin与Java虚拟机三:控制流benchmark_cc2 小时前
单只股票五档盘口接入个人研究仓库:QuantDash 读取、校验与易错点xiaoye-duck3 小时前
《C++ 项目:手写大模型接入 SDK》Ollama接口设计(上):初始化、全量响应实现和测试总要学点什么4 小时前
第98篇:三维特效-材质线效果——给一条线换十种材质,虚线的图案只填了一半田甲4 小时前
做一款 Type-C 母座读卡器:GL3224 双卡方案实测青少儿编程课堂4 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:中缀表达式求值解析严肃小白兔4 小时前
MATLAB 绘图与科研论文插图制作:图形设计、统计表达与矢量导出