Python Excel

Home   openpyxl Tutorial   Contact us

Open a Workbook with Openpyxl load_workbook Function


Python openpyxl load_workbook( ) function is used when you have to access an MS Excel file in openpyxl module. You have to keep in mind that load workbook function only works if you have an already created file on your disk and you want to open workbook for some operation.

Python Excel Training


How to use load workbook ( ):

  1. To use load workbook function you should know the name of Excel file you want to work on.
  2. You should know the path of file.
  3. Use load_workbook(path+name) to create a reference to that particular Excel file
  4. Use the reference to read, write, create a new sheet, delete a sheet etc etc.

Example for load workbook with code:


1. Ofcourse you would know the name of file you want to open for working. The file will have .xlsx extension. e.g  myfile.xlsx

2.  Where the file is located on your drive. Now either the file is located in your python current working directory in this case you don't have to give the path and just write the file name as an argument to this function.

import openpyxl

ref_workbook= openpyxl.load_workbook('myfile.xlsx')


If your file is not in your python working directory first see where the file is stored. Write path for the file and give it as a parameter to load workbook.

path='c:/files/pythonexcel/myfile.xlsx'

ref_workbook=openpyxl.load_workbook(path)

Now you can use this reference   ref_workbook  to access myfile.xlsx and read or write or add or delete sheets, or cells or any other thing you want to do. Here is how you can read or write to a file in openpyxl


If you want to Read, Write and Manipulate(Copy, cut, paste, delete or search for an item etc) Excel files in Python with simple and practical examples I will suggest you to see this simple and to the point Python Excel Openpyxl Course with examples about how to deal with MS Excel files in Python. This video course teaches efficiently how to manipulate excel files and automate tasks.

Everything you do in Microsoft Excel, can be automated with Python. So why not use the power of Python and make your life easy. You can make intelligent and thinking Excel sheets, bringing the power of logic and thinking of Python to Excel which is usually static, hence bringing flexibility in Excel and a number of opportunities.