Open a Workbook with Openpyxl
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
- To use load workbook function you should know the name of
Excel file you want to work on.
- You should know the path of file.
- Use load_workbook(path+name) to create a reference to that
particular Excel file
- 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.
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 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.