| 123456789101112131415161718192021222324252627 |
- import xlrd
- from common.exceptions import ExcelFileError
- def check_excel_file(file):
- sheets_names = ['oferta', 'existentes', 'mct', 'rtr']
- try:
- xls = xlrd.open_workbook(file, on_demand=True)
- sheets = xls.sheet_names()
- except Exception:
- raise ExcelFileError(file)
- else:
- not_found = []
- for sheet in sheets_names:
- sheet_exists = sheet in sheets
- if not sheet_exists:
- not_found.append(sheet)
- if not_found:
- msg = 'El archivo no contiene la(s) hoja(s) '
- msg += f'<{", ".join(sheet for sheet in not_found)}>'
- raise ExcelFileError(
- file,
- message=msg)
|