warnings.warn("Discarded range with reserved name")
[u'Interim Testing', u'Year End Testing']
echo 'xlsx/SOX Controls Testing Template.xlsx'  0.00s user 0.00s system 41% cpu 0.002 total
python sheet_names_openpyxl.py  0.24s user 0.11s system 10% cpu 3.424 total

> \ls -1 **/*.xls? | python sheet_names_openpyxl.py --verbosity=info
> find . -print | python sheet_names_openpyxl.py --verbosity=info
> ls -d -1 **/*.*
"""
from sheet_names_api import main


def _openpyxl(filepath):
    import openpyxl
    # https://openpyxl.readthedocs.org/en/2.3.3/optimized.html
    try:
        wb = openpyxl.load_workbook(filepath, read_only=True)
    # InvalidFileException: openpyxl does not support .txt file format, please check you can open it with Excel first. Supported formats are: .xlsx,.xlsm,.xltx,.xltm
    # InvalidFileException: openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.
    # BadZipfile: File is not a zip file
        return wb.get_sheet_names()
    except Exception as e:
        # Ignore unsupported files
        if 'openpyxl does not support' in repr(e):
            pass
        # if 'openpyxl does not support the old .xls file format' in repr(e):
        #     pass

if __name__ == '__main__':
    main(_openpyxl)
  "1.2309041023254395": "xlsx/SOX Testing Status.xlsx",
  "1.5334298610687256": "xlsm/Compare XML.xlsm"
}
"""
from sheet_names_api import main


def _xlrd(filepath):
    import xlrd
    # https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html?p=4966
    # with xlrd.open_workbook(filepath, on_demand=True, ragged_rows=True) as wb:
    #     sheet_names = wb.sheet_names()
    #     return sheet_names

    # How about with memory mapping? Nope, blows up on both xls and xlsx
    import contextlib
    import mmap
    import os
    length = 2**10 * 4
    # length = 0  # whole file
    with open(filepath, 'rb') as f:
        # mmap throws if length is larger than file size
        length = min(os.path.getsize(filepath), length)
        with contextlib.closing(mmap.mmap(f.fileno(), length, access=mmap.ACCESS_READ)) as m,\
             xlrd.open_workbook(on_demand=True, file_contents=m) as wb:
            sheet_names = wb.sheet_names()
            return sheet_names

if __name__ == '__main__':
    main(_xlrd, ['xls/SMITH 2014 TRIP-Master List.xls'])