Open Source Python API for Spreadsheets
Python library for reading and formatting XLS & XLSX file format.
Xlrd is an open source python API for reading & formatting Microsoft Excel (XLS, XLSX) file format. The API allows the Python developer to read Excel files, handle Unicode in it, manage dates, format cells & columns, use constants, formulas, macros, and more. Furthermore, the API provides loading worksheets with on-demand functionality that allows developers to save memory by loading only the required sheets.
The developer no more maintains the API, and corrupted & non-standard Excel files will not work with this API. The API will ignore VBA modules, comments, hyperlinks, autofilters, advance filters, and few other excel features as well.
Getting Started with Xlrd
You need to have Python 2.7 or 3.4+ or higher installed on your system to run Xlrd smoothly. The recommended way to install via PIP. Please use the following command.
Install Xlrd via PIP Command
pip install xlrd
Read Excel Worksheets via Free Python API
Xlrd API allows reading Microsoft Excel XLS & XLSX files using Python. The developers can easily open existing workbooks using xlrd.open_workbook() method. You can get worksheets and sheet names of your excel file using workbook.nsheets & workbook.sheet_names properties respectively. In order to read rows & columns, you can select a sheet by using workbook.sheet_by_index() method and use worksheet.nrows & worksheet.ncols respectively.
Open & Acccess Contents of Excel Workbook via Python API
from mmap import mmap,ACCESS_READ from xlrd import open_workbook print open_workbook('simple.xls') with open('simple.xls','rb') as f: print open_workbook( file_contents=mmap(f.fileno(),0,access=ACCESS_READ) ) aString = open('simple.xls','rb').read() print open_workbook(file_contents=aString)
Load Worksheets on Demand using Python
The Open Source spreadsheet library Xlrd allows software developers to load worksheets on demand. The functionality reduces memory usage and loads only required worksheets. You can use on-demand load functionality by using on_demang argument.
Work with Large Excel Workbook via Python API
from xlrd import open_workbook book = open_workbook('simple.xls',on_demand=True) for name in book.sheet_names(): if name.endswith('2'): sheet = book.sheet_by_name(name) print sheet.cell_value(0,0) book.unload_sheet(name
Formatting Informatin in Excel using Python
Xlrd library gives developers the capability to read, display & render excel spreadsheet contents on a screen or to another file without losing the ability to display/render it. Default formatting is applied to all empty cells. The API firstly will use Rowinfo & Colinfo class to get the properties. If Rowinfo & Colinfor class properties are not available the API will use the default properties.