Skip to content

Commit

Permalink
search: Use the python xlrd module to read .xls files.
Browse files Browse the repository at this point in the history
xls2csv is broken.
  • Loading branch information
mtwebster committed Dec 3, 2021
1 parent 074820d commit b9aca27
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Depends:
odt2txt,
catdoc,
untex,
python3-xlrd,
${misc:Depends},
${shlibs:Depends},
Recommends:
Expand Down
7 changes: 7 additions & 0 deletions search-helpers/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ ppt_to_txt = executable('nemo-ppt-to-txt',
install: true
)

install_data(
'nemo-xls-to-txt',
install_dir: join_paths(get_option('prefix'), get_option('bindir')),
install_mode: 'rwxr-xr-x'
)

install_data(
'mso.nemo_search_helper',
'mso-ppt.nemo_search_helper',
'mso-xls.nemo_search_helper',
install_dir: join_paths(nemoDataPath, 'search-helpers')
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Nemo Search Helper]
TryExec=xls2csv;
Exec=xls2csv %s
TryExec=nemo-xls-to-txt;
Exec=nemo-xls-to-txt %s
MimeType=application/vnd.ms-excel;
Priority=100
31 changes: 31 additions & 0 deletions search-helpers/nemo-xls-to-txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python3
import sys
import xlrd
import locale

path = sys.argv[1]

try:
book = xlrd.open_workbook(path)
except Exception as e:
print("Can't read '%s': %s" % (path, e))
exit(1)

date_format = locale.nl_langinfo(locale.D_FMT)

for sheet in book.sheets():
for row in sheet.get_rows():
had_content = False
for cell in row:
if cell.ctype == xlrd.XL_CELL_TEXT:
print(cell.value, end=" ")
had_content = True
elif cell.ctype == xlrd.XL_CELL_DATE:
dt = xlrd.xldate_as_datetime(cell.value, 0)
print(dt.strftime(date_format), end=" ")
had_content = True

if had_content:
# end of row newline (but only if the row wasn't blank)
print("")
exit(0)
1 change: 0 additions & 1 deletion search-helpers/third-party/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ helpers = [
'id3.nemo_search_helper',
'libreoffice.nemo_search_helper',
'mso-doc.nemo_search_helper',
'mso-xls.nemo_search_helper',
'pdf2txt.nemo_search_helper',
'pdftotext.nemo_search_helper',
'ps2ascii.nemo_search_helper'
Expand Down

0 comments on commit b9aca27

Please sign in to comment.