本帖最后由 逃兵 于 2020-11-12 17:01 编辑
中间加了几行代码,是要统计这个吗
#coding=gbk
import openpyxl
from openpyxl.utils import column_index_from_string
filename = r'./waf策略统计.xlsx'
tongji = openpyxl.load_workbook( filename )
#——————————————服务器ip:10.254.221.140————————————————————————————————————————
tongji1 = tongji['Sheet1']
maxtongji_hang = tongji1.max_row
daochu = openpyxl.load_workbook( r'./waf导出日志.xlsx' )
daochu1 = daochu['Sheet1']
maxdaochu_hang = daochu1.max_row
maxdaochu_lie = daochu1.max_column
for i in range(2,maxdaochu_hang + 1):
tongji1.cell(maxtongji_hang + 1,column_index_from_string('A')).value = maxtongji_hang + 0
if daochu1.cell(i,column_index_from_string('C')).value == '10.254.221.140':
tongji1.cell(2,column_index_from_string('B')).value = daochu1.cell(i,column_index_from_string('C')).value
maxtongji_hang += 1
times = 0
file_value={}
for each_line in daochu1:
for each in each_line:
if each.value != None:
file_value[each] = str(each.value)
for i in file_value:
if '10.254.221.140' in file_value[i]:
times+=1
print('10.254.221.140 出现了%s次'%times)
print(i)
tongji.save('./xin.xlsx')
|