-
Notifications
You must be signed in to change notification settings - Fork 5
/
search.py
40 lines (30 loc) · 1.16 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import xlrd
import argparse
def find(path, word):
l = []
d = os.listdir(path)
for file in d:
filename = str(path) +'/' + str(file)
if filename.endswith('.xlsx') or filename.endswith('.xls'):
wb = xlrd.open_workbook(filename)
print('Finding in %s, Sheets:%d' % (file,len(wb.sheets())))
for ws in wb.sheets():
for i, row in enumerate(range(ws.nrows)):
for j, col in enumerate(range(ws.ncols)):
if str(word) in str(ws.cell_value(i, j)):
l.append((file,ws.name,row,col))
if l:
print ('Word %s found %d times in:' %(word,len(l)))
for fn, sheet,row, col in l:
print ('File: %s, Sheet %s, row: %s ,column: %s' %(fn,sheet,row,col))
else:
print ('Word %s not found' %word)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("path", help="Path to folder with files.")
parser.add_argument("word", help="Word to search in xlsx files.")
args = parser.parse_args()
find(args.path, args.word)