Xlrderror: can’t find workbook in ole2 compound document

The “xlrderror: can’t find workbook in ole2 compound document” error typically occurs when the xlrd library is unable to locate the workbook file within the provided ole2 compound document.

To further understand this error, let’s break down its possible causes and solutions:

  1. Incorrect File Path: Ensure that the file path provided to open the workbook is correct. Make sure the file is located in the specified location and the path is accurate.


    import xlrd

    file_path = "path/to/workbook.xls"
    workbook = xlrd.open_workbook(file_path)

  2. Unsupported Excel File Format: The xlrd library only supports certain Excel file formats, such as .xls (Excel 97-2003) and .xlsx (Excel 2007+). If you are trying to open a file in an unsupported format, this error may occur. Make sure you are using a compatible file format.


    import xlrd

    file_path = "path/to/workbook.xlsx"
    workbook = xlrd.open_workbook(file_path)

  3. Corrupted Workbook: If the Excel workbook file is corrupted or damaged, xlrd may not be able to read it properly. Try opening the file in Excel and check if it displays any warnings or errors. If the file is indeed corrupted, consider using a backup or recovering the file before attempting to access it with xlrd.

By addressing the above possible causes, you should be able to resolve the “xlrderror: can’t find workbook in ole2 compound document” error. Remember to double-check the file path, ensure compatibility with supported file formats, and verify that the workbook is not corrupted or damaged.

Here’s an example of opening an Excel workbook using xlrd library:


import xlrd

file_path = "path/to/workbook.xls"
workbook = xlrd.open_workbook(file_path)
sheet = workbook.sheet_by_index(0)

# Accessing data from the first sheet
for row in range(sheet.nrows):
  for col in range(sheet.ncols):
    cell_value = sheet.cell_value(row, col)
    print(cell_value)

Read more interesting post

Leave a comment