Working with Python and Excel
Note: The instructions are for python3.x on Ubuntu
There are several different libraries you can use to easily work with Excel. I will be covering openpyxl. Other options include xlsxwriter, xlrd, xlwt, and xltuils.
To install openpyxl, make sure you have pip3 installed:
If pip3 is not installed, install it first:
sudo apt-get install python3-pip
Once pip3 is installed:
sudo pip3 install openpyxl
Reading from Excel
See the following code
from openpyxl import load_workbook wb = load_workbook(filename = 'Tab-9.xlsx') sheet_ranges = wb['Tb 9'] print(sheet_ranges['C5'].value)
This code opens the worksheet "Tb 9" in the file "Tab-9.xlsx" and prints the value of the cell C5.