Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Working with Excel Files


First, we should create the workbook we'll work on. In the last part, we imported the load_workbook function. This time, we have to import the Workbook object from openpyxl:

from openpyxl import Workbook

We'll simply assign it to the wb variable:

wb = Workbook()

This object only exists in the memory of our program. Everything we do on that object (e.g. adding new sheets and filling them with data) will be lost if we don't save it in a file. We can do this with the save() method:"filename.xlsx")

As you can see, we invoke the method on the workbook object. The save() method takes only one argument – the name of the file where it will save the workbook contents. Important: If the file name in the save() argument already exists in a given folder, it will be overwritten.


Import the Workbook object. Create a new workbook and assign it to the wb variable. Then save your workbook to a file named budget.xlsx.