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
相关推荐
老毛肚17 小时前
jeecg-boot-base-core 02 dayyaoxin52112317 小时前
434. Java 日期时间 API - Period 基于日期的时间段凡人叶枫18 小时前
Effective C++ 条款30:透彻了解 inlining 的里里外外学逆向的18 小时前
C++纯虚函数岁月宁静19 小时前
RAG 文档摄入全链路,从原理到生产落地程序员二叉19 小时前
【JUC】ThreadLocal底层原理|内存泄漏|弱引用|跨线程传递方案程序员二叉19 小时前
【JUC】线程池全套深度详解|参数|流程|拒绝策略|调优|异常处理JaydenAI19 小时前
[对比学习LangChain和MAF-07]如何引入人机交互的审批流程神奇元创19 小时前
商用级光路加速卡:大模型推理的极速落地方案凡人叶枫19 小时前
Effective C++ 条款22:将成员变量声明为 private