Create Excel in Python

In this Python tutorial, we will study about how we can create excel in Python­­­­­­­. Excel is a very popular tool which we deal with in our daily office life. Lots of problems can be solved with excel with very ease.

First, we will see that how we can create an excel file from Python. There are so many libraries in Python which we can use for excel like openpyxl, xlsxwriter, xlrd, xlwt, xlutils. You can use any of these python excel libraries.

We will use here openpyxl for reading and writing excel through Python.

How to Install openpyxl?

Openpyxl is Python library, if you don’t have openpyxl library you can download it via pip.

pip install openpyxl

The above command will install openpyxl into your system.

Now open your favorite Python Editor to hands-on on Python excel programs.

How to create an Excel in Python?

Step 1: First we create an excel file from Python. To use openpyxl library, we need to import it into our program.

from openpyxl import Workbook

we imported Workbook from openpyxl, as excel is called Workbook, inside Workbook we have worksheets like  sheet1, sheet2.. etc.


Step2: create object of Workbook.

After import Workbook, we will create object of Workbook.

wb=new Workbook()


Step 3: Save the Workbook.

Now we have created workbook object in step 2, its time to save the file in some location

# Save the excel file'D:\\Python\\test.xlsx')


we are going to save excel file inside python folder in D drive in window with filename =”test.xlsx”.


so overall program, is

[code language=”python”]

#Python excel simple program
#import Workbook
from openpyxl import Workbook
wb = Workbook()

# Save the excel file‘D:\\Python\\test.xlsx’)


Above program will create empty excel file in specified location.

Scroll to Top