Here are resources for more information about working with virtual environments, pip and bpython:
Starting With "Hello World"
To get started with
openpyxl, create a virtual environment in a new folder. I’m going to use
venv, but you can use any environment manager.
00:11 Once you have it, go ahead and activate it
pip install openpyxl. I’m also going to grab
bpython to clean up some terminal sessions later.
While that’s installing, go ahead and make a new file. I’m going to call mine
hello_openpyxl.py Inside this new file, I’m going to say
from openpyxl import Workbook()
and then define
workbook as a new
sheet will equal
sheet, say that
"A1" is equal to
"hello", and then
"B1" is going to be equal to
If this doesn’t make sense, don’t worry. We’re going to talk about it in a little bit. Finally, say
workbook.save() and pass it in the
Save this, and then go ahead and run it. Okay. If everything went well, you should have a new file called
"hello_world.xlsx". If you go to open that up, you should see hello and world! in A1 and B1. All right!
You’ve just made your first spreadsheet using
openpyxl. If we go back here, we can see that the spreadsheet, or
Workbook, is a class inside
openpyxl, and then within each
Workbook is a number of sheets. Here, by taking the active sheet in the workbook, you’ve just selected whichever sheet is open when you open the workbook normally. Each sheet is then broken up into a number of cells, which here are
"B1", and then these cells are organized into rows and columns, which are represented by letters for columns and numbers for the rows.
Before we finish up in this video, go ahead and download the sample Excel worksheet from the resources (Supporting Material) tab. It contains a number of reviews of watches from Amazon, and you’ll use that to practice the different features of
Become a Member to join the conversation.