Answers:
我用ssconvert工具制作了一个(来自Gnumeric)。您需要先安装Gnumeric:
sudo apt-get install gnumeric
您可以将内容保存为脚本并调用:
./script-find-in-xls.sh text
脚本的内容。
#!/bin/sh
# $1 - text to find
if [ -z "$1" ]
then
echo 'Please, the text is mandatory'
exit 1
fi
rm -rf /tmp/xls-csv/
mkdir /tmp/xls-csv/
cd /tmp/xls-csv/
cp /location/of/excel-files/*.xls /tmp/xls-csv/
for f in *.xls; do
ssconvert -S --import-encoding=ISO8859-1 ./"$f" ./"${f%.xls}.csv"
done
cat *.csv.* > all-xls-content.txt
rm *.csv.*
if cat all-xls-content.txt | egrep --color $1; then
echo 'found'
else
echo 'not found'
fi
该脚本转换csv文件中的所有xls文件,将csv文件加入单个文件并使用 egrep
找到文字。
代码不完美,但做的工作。
我遇到过同样的问题。运行此脚本:
python search.py /home/user/directory string
在这里你找到我的解决方案
#!/usr/bin/python
import os, sys
import xlrd
def find(path, word):
l = []
d = os.listdir(path)
for file in d:
filename = str(path) +'/' + str(file)
print ('Finding in %s' %file)
if filename.endswith('.xlsx'):
wb = xlrd.open_workbook(filename)
ws = wb.sheet_by_index(0)
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,row,col))
if l:
print ('Word %s found %d times in:' %(word,len(l)))
for fn, row, col in l:
print ('File: %s, row: %s ,column: %s' %(fn,row,col))
else:
print ('Word %s not found' %word)
if __name__ == "__main__":
try:
find (sys.argv[1],sys.argv[2])
except IndexError:
print('\tExecute: python searchpy <path> <word>')
print('\tEg: python searchpy /home/user/files/ Fox')
你可以从Github拉: searb功能于XLSX