diff --git a/import_export/formats/base_formats.py b/import_export/formats/base_formats.py index 10b5447eb..f5e7c2412 100644 --- a/import_export/formats/base_formats.py +++ b/import_export/formats/base_formats.py @@ -22,14 +22,12 @@ try: - from tablib.compat import openpyxl - + import openpyxl XLSX_IMPORT = True except ImportError: try: - import openpyxl # NOQA - - XLSX_IMPORT = True + from tablib.compat import openpyxl + XLSX_IMPORT = hasattr(openpyxl, 'load_workbook') except ImportError: xlsx_warning = "Installed `tablib` library does not include" "import support for 'xlsx' format and openpyxl module is not found." @@ -211,8 +209,7 @@ def create_dataset(self, in_stream): """ assert XLSX_IMPORT from io import BytesIO - from openpyxl import load_workbook - xlsx_book = load_workbook(BytesIO(in_stream)) + xlsx_book = openpyxl.load_workbook(BytesIO(in_stream)) dataset = tablib.Dataset() sheet = xlsx_book.active