Skip to content
Home » openpyxl Part 1 – A Simple Workbook

openpyxl Part 1 – A Simple Workbook

Spread the love

In this series we’ll be using the openpyxl module to work on spreadsheets. In this part we’ll install the module and create a simple workbook. I will use the terms spreadsheet and workbook interchangeably throughout the series.

Spreadsheets are used a lot in all domains of science to manipulate large datasets easily and without prior technical background necessary to get started.

openpyxl workbook

If you don’t have the openpyxl module on your machine yet, go to the terminal and install it:

pip install openpyxl

With the module installed let’s make sure everything works. Let’s create a spreadsheet. First we need 

to import the Workbook class from the openpyxl module:

xxx

from openpyxl import Workbook

Now we can create an object of the Workbook class, which represents the spreadsheet:

workbook = Workbook()

Now let’s assign the active worksheet to a variable. Each spreadsheet may consist of one or more sheets:

sheet = workbook.active

Your Panda3D Magazine

Make Awesome Games and Other 3D Apps

with Panda3D and Blender using Python.

Cool stuff, easy to follow articles.

Get the magazine here (PDF).

We set the content of the cells using the coordinates of the columns and rows:

sheet['A1'] = 'first cell'
sheet['C2'] = 'It works!'

Finally we have to save the file:

workbook.save(filename = 'first.xlsx')

This creates a spreadsheet file in your current directory. You can now go there and open it by double-clicking on the icon for example.

That’s it. We’ll have a look at all the steps described above in much more detail in later parts of the series.

Python Jumpstart Course

Learn the basics of Python, including OOP.

with lots of exercises, easy to follow

The course is available on Udemy.

Blender Jumpstart Course

Learn the basics of 3D modeling in Blender.

step-by-step, easy to follow, visually rich

The course is available on Udemy and on Skillshare.


Spread the love

Leave a Reply