Python Excel

Home   openpyxl Tutorial   Contact us

Openpyxl load_workbook()

In this tutorial you will learn how to open an Excel xlsx workbook in Python with 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.

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: Open workbook with load_workbook

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.



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 or value 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.

Automate your Excel Tasks and save Time and Effort. You can save dozens or hundreds of hours by Python Excel Automation with just a single click get your tasks done with in seconds which used to take hours of Manual Excel and Data Entry Work.

Do you have to automate excel tasks, or you want python to read Microsoft Excel, csv files, search, match sort data and write in a new Excel file you may please click here to contact us.

We also provide 1 to 1 live online Training at Skype for Python.