pyxlsb is an Excel 2007-2010 Binary Workbook (xlsb) parser for
Python. The library is currently extremely limited, but functional
enough for basic data extraction.
pip install pyxlsbThe module exposes an open_workbook(name) method (similar to Xlrd
and OpenPyXl) for opening XLSB files. The Workbook object representing
the file is returned.
from pyxlsb import open_workbook
with open_workbook('Book1.xlsb') as wb:
# Do stuff with wbThe Workbook object exposes a get_sheet(idx) method for retrieving a
Worksheet instance.
# Using the sheet index (1-based)
with wb.get_sheet(1) as sheet:
# Do stuff with sheet
# Using the sheet name
with wb.get_sheet('Sheet1') as sheet:
# Do stuff with sheetTip: A sheets property containing the sheet names is available on
the Workbook instance.
Each cell now exposes metadata fields: validation, cell_type, format, and constraints. This allows downstream libraries (like pandas) to assign datatypes based on Excel's intended validation/type.
for row in sheet.rows():
for cell in row:
print(cell)
# Cell(r=0, c=0, v='TEXT', validation='Text', cell_type='str', format='General', constraints=None)You can retrieve validation info for a specific cell:
info = sheet.get_cell_validation(0, 0)
print(info)
# {'validation': 'Text', 'cell_type': 'str', 'format': 'General', 'constraints': None}Do note that dates will appear as floats. You must use the
convert_date(date) method from the pyxlsb module to turn them
into datetime instances.
from pyxlsb import convert_date
print(convert_date(41235.45578))
# datetime.datetime(2012, 11, 22, 10, 56, 19)