def get_spreadsheet(filename): try: with open_any_workbook(filename) as workbook: yield WorksheetWrapper.from_workbook(workbook) except SpreadsheetFileEncrypted as e: raise ImporterExcelFileEncrypted(e.message) except SpreadsheetFileNotFound as e: raise ImporterFileNotFound(e.message) except SpreadsheetFileInvalidError as e: raise ImporterExcelError(e.message)
def check_file(self): """ open a spreadsheet download ref just to test there are no errors opening it :raise ImporterError subtypes """ tempfile = self.get_tempfile() if not tempfile: raise ImporterFileNotFound('file not found in cache') open_spreadsheet_download_ref(tempfile)