pandas/io/excel/_base.py
def inspect_excel_format(
    content_or_path: FilePathOrBuffer,
    storage_options: StorageOptions = None,
) -> str:
    """
    Inspect the path or content of an excel file and get its format.

    Adopted from xlrd: https://github.com/python-excel/xlrd.

    Parameters
    ----------
    content_or_path : str or file-like object
        Path to file or content of file to inspect. May be a URL.
    {storage_options}

    Returns
    -------
    str
        Format of file.

    Raises
    ------
    ValueError
        If resulting stream is empty.
    BadZipFile
        If resulting stream does not have an XLS signature and is not a valid zipfile.
    """
    if isinstance(content_or_path, bytes):
        content_or_path = BytesIO(content_or_path)

    with get_handle(
        content_or_path, "rb", storage_options=storage_options, is_text=False
    ) as handle:
        stream = handle.handle
        stream.seek(0)
        buf = stream.read(PEEK_SIZE)
        if buf is None:
            raise ValueError("stream is empty")
        else:
            assert isinstance(buf, bytes)
            peek = buf
        stream.seek(0)

        if peek.startswith(XLS_SIGNATURE):
            return "xls"
        elif not peek.startswith(ZIP_SIGNATURE):
            raise ValueError("File is not a recognized excel file")

        # ZipFile typing is overly-strict
        # https://github.com/python/typeshed/issues/4212
        zf = zipfile.ZipFile(stream)  # type: ignore[arg-type]

        # Workaround for some third party files that use forward slashes and
        # lower case names.
        component_names = [name.replace("\\", "/").lower() for name in zf.namelist()]

        if "xl/workbook.xml" in component_names:
            return "xlsx"
        if "xl/workbook.bin" in component_names:
            return "xlsb"
        if "content.xml" in component_names:
            return "ods"
        return "zip"

    Inspect the path or content of an excel file and get its format.

    Adopted from xlrd: https://github.com/python-excel/xlrd.

    Parameters
    ----------
    content_or_path : str or file-like object
        Path to file or content of file to inspect. May be a URL.
    {storage_options}

    Returns
    -------
    str
        Format of file.

    Raises
    ------
    ValueError
        If resulting stream is empty.
    BadZipFile
        If resulting stream does not have an XLS signature and is not a valid zipfile.
    
Inspect the path or content of an excel file and get its format.

Parameters

content_or_path : str or file-like object
Path to file or content of file to inspect. May be a URL.

Returns

str
Format of file.

Raises

ValueError
If resulting stream is empty.
BadZipFile
If resulting stream does not have an XLS signature and is not a valid zipfile.
Inspect the path or content of an excel file and get its format . Parameters content_or_path : str or file - like object Path to file or content of file to inspect . May be a URL . Returns str Format of file . Raises ValueError If resulting stream is empty . BadZipFile If resulting stream does not have an XLS signature and is not a valid zipfile .
def inspect_excel_format(
    content_or_path: FilePathOrBuffer,
    storage_options: StorageOptions = None,
) -> str:
    if isinstance(content_or_path, bytes):
        content_or_path = BytesIO(content_or_path)
    with get_handle(
        content_or_path, "rb", storage_options=storage_options, is_text=False
    ) as handle:
        stream = handle.handle
        stream.seek(0)
        buf = stream.read(PEEK_SIZE)
        if buf is None:
            raise ValueError("stream is empty")
        else:
            assert isinstance(buf, bytes)
            peek = buf
        stream.seek(0)
        if peek.startswith(XLS_SIGNATURE):
            return "xls"
        elif not peek.startswith(ZIP_SIGNATURE):
            raise ValueError("File is not a recognized excel file")
        zf = zipfile.ZipFile(stream)  
        component_names = [name.replace("\\", "/").lower() for name in zf.namelist()]
        if "xl/workbook.xml" in component_names:
            return "xlsx"
        if "xl/workbook.bin" in component_names:
            return "xlsb"
        if "content.xml" in component_names:
            return "ods"
        return "zip"
def inspect_excel_format ( content_or_path : FilePathOrBuffer , storage_options : StorageOptions = None , ) -> str : if isinstance ( content_or_path , bytes ) : content_or_path = BytesIO ( content_or_path ) with get_handle ( content_or_path , "rb" , storage_options = storage_options , is_text = False ) as handle : stream = handle . handle stream . seek ( 0 ) buf = stream . read ( PEEK_SIZE ) if buf is None : raise ValueError ( "stream is empty" ) else : assert isinstance ( buf , bytes ) peek = buf stream . seek ( 0 ) if peek . startswith ( XLS_SIGNATURE ) : return "xls" elif not peek . startswith ( ZIP_SIGNATURE ) : raise ValueError ( "File is not a recognized excel file" ) zf = zipfile . ZipFile ( stream ) component_names = [ name . replace ( "\\" , "/" ) . lower ( ) for name in zf . namelist ( ) ] if "xl/workbook.xml" in component_names : return "xlsx" if "xl/workbook.bin" in component_names : return "xlsb" if "content.xml" in component_names : return "ods" return "zip"
Inspect the path or content of an excel file and get its format.
Inspect the path or content of an excel file and get its format .
"""
    Inspect the path or content of an excel file and get its format.

    Adopted from xlrd: https://github.com/python-excel/xlrd.

    Parameters
    ----------
    content_or_path : str or file-like object
        Path to file or content of file to inspect. May be a URL.
    {storage_options}

    Returns
    -------
    str
        Format of file.

    Raises
    ------
    ValueError
        If resulting stream is empty.
    BadZipFile
        If resulting stream does not have an XLS signature and is not a valid zipfile.
    """ # ZipFile typing is overly-strict # https://github.com/python/typeshed/issues/4212 # type: ignore[arg-type] # Workaround for some third party files that use forward slashes and # lower case names.
content_or_path
FilePathOrBuffer
storage_options
StorageOptions