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
相关推荐
艾为电子2 分钟前
【技术帖】让接口不再短命:艾为 C-Shielding™ Type-C智能水汽防护技术解析ZTL-NPU9 分钟前
Jetbrains开发ros棉花骑士24 分钟前
【AI Agent】面向 Java 工程师的Claude Code Harness 学习指南IGAn CTOU29 分钟前
PHP使用Redis实战实录2:Redis扩展方法和PHP连接Redis的多种方案环黄金线HHJX.1 小时前
TSE框架配置与部署详解Vfw3VsDKo1 小时前
Maui 实践:Go 接口以类型之名,给 runtime 传递方法参数前端摸鱼匠1 小时前
YOLOv11与OpenCV 联动实战:读取摄像头实时视频流并用 YOLOv11 进行检测(三)Pyeako1 小时前
PyQt5 + PaddleOCR实战:打造桌面级实时文字识别工具喝凉白开都长肉的大胖子2 小时前
在 Matplotlib 中fontweight一般怎么设置白藏y2 小时前
【C++】muduo接口补充