From f6d7888d9e28222b8df9c5ba5359e358e9c1677b Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Thu, 14 Jul 2011 13:47:07 -0500 Subject: [PATCH] Added xls detection. --- tablib/formats/_xls.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tablib/formats/_xls.py b/tablib/formats/_xls.py index 1282a43..c801658 100644 --- a/tablib/formats/_xls.py +++ b/tablib/formats/_xls.py @@ -112,3 +112,11 @@ def dset_sheet(dataset, ws): ws.write(i, j, col) +def detect(stream): + """Returns True if given stream is valid XLS.""" + + try: + xlrd.open_workbook(file_contents=stream) + return True + except xlrd.XLRDError: + return False