
Explore the ins and outs of OpenPyXL to control Excel with Python, practice hands-on coding, download source files, and participate in discussion forums to deepen understanding.
Install Python from python.org, install OpenPyXL with pip, and install an Excel viewer such as Microsoft Excel or OpenOffice; start using OpenPyXL to automate Excel documents.
Always back up your workbooks when using OpenPyXL to prevent data loss, since there is no undo button, and errors can overwrite your original data.
Explore workbooks and worksheets by creating, opening, saving, and copying them, then access sheets by name and indexes and obtain references to workbooks and sheets.
Learn to create and save workbooks in openpyxl by importing the library, instantiating a workbook object, saving as first workbook.xlsx, and viewing the default sheet in Excel.
Learn to create and open workbooks, add and remove sheets, rename them, access sheets by index or name, copy worksheets, and enumerate sheet titles with openpyxl.
Learn to read data from Excel cells using absolute and relative references, with examples like A1 and C2, then apply offset and read a full data range.
Learn absolute and relative cell references in openpyxl by creating a workbook, selecting a sheet, and setting A1 and C3 values; use utils to convert column letters and indices.
Master iterating OpenPyXL cells with iter_rows and iter_cols, using min_row, max_row, min_col, max_col, and the values_only option to obtain row tuples and column outputs.
Learn to use OpenPyXL to get maximum row and column with max_row and max_column, print results, and handle closing workbooks, as seen with A1 to C4 and 1 to 12.
Learn to delete and insert rows and columns, use append to insert rows, move and copy ranges of cells, and insert formulas and tables into spreadsheets.
In this lecture, we are inserting and deleting rows and columns. Note that OpenPyXL has changed from a 0-based index to a 1-based index when inserting and deleting rows. The source code is updated to reflect these changes but the video shows the 0-based index usage.
Learn to move and copy cell ranges in openpyxl by offsetting ranges like A1:J10, moving cells, and duplicating values with iter_rows and worksheet cells.
Insert formulas in openpyxl and transpose them, set A11 to =SUM(A1:A10), move and transpose cell references with the translate parameter, then save and review results.
Congratulations on reaching half the course. Post questions or comments in the discussion forum, offer feedback as a review, and continue studying.
Learn cell formatting in Excel, including color, font, size, and data formats, copy and merge cells, apply autofilter for sorting, use the fold method, and configure page setups for printing.
Learn how to format cells in openpyxl, including fonts, fills, borders, alignment, and number formats, and implement workbook and sheet protection with passwords.
CORRECTION: In the video we are setting the old_cell font to
old_cell.font = Font(name='Arial', size=18, color=colors.RED).
Since then OpenPyXL has updated to not use the colors constants RED, BLUE etc.
Instead we have to write the colors as a HEX value. The code for red is "FF0000" and thus the new line becomes:
old_cell.font = Font(name="Arial", size=18, color="FF0000")
https://www.rapidtables.com/web/color/RGB_Color.html has a picker as well as a table for HEX colors.
Learn to merge and unmerge cells in OpenPyXL, using range borders like A1:B1 and A1:C4, and understand how merging preserves the upper-left value while discarding others.
Learn how to apply autofilter. Sorting cannot currently be done with OpenPyXL. I have attached the file 6.4_resources.py that contains the Win32 library that can apply the sort.
Learn to configure print page setups in openpyxl by applying paper size, orientation, and margins to sheets or workbooks, using page_setup options and predefined constants.
Group columns and rows in OpenPyXL with the group method, using A to D and rows 1 to 10. Explain that ungrouping is manual.
Create charts such as pie charts and bar charts, then place them on a chart sheet, and insert images into Excel using OpenPyXL.
Create bar, scatter, and pie charts in openpyxl by defining data references, configuring series, and placing charts with titles and axis labels.
Create a chart sheet in openpyxl by moving a chart to a sheet with data. Build an area chart using references and add it to the chart sheet with cs.add_chart.
Install the pillow library, import image from openpyxl.drawing.image, create an image object, insert it into cell C10, then save and view the workbook.
Explore essential Python code for OpenPyXL workflows, including Tkinter file dialogs and script timing. Note this is not an OpenPyXL chapter, but it covers creating files, folders, and retrieving names.
Use tkinter file dialogs to open or save Excel workbooks with openPyXL, employing ask open file name and ask save as, and set the initial directory.
Learn to use pathlib to manage file paths and join the current working directory with file names. Retrieve files by extension with glob and open and read them in Python.
apply pathlib to open multiple files from a list, join their paths, and read each line with with open. learn how enumerate can provide indices while iterating over file paths.
Time your Python scripts with the time module to measure OpenPyXL operations, using start and end timestamps. Observe how results vary with input size and avoid background processes.
Start Excel for viewing your work using Python and the os module to launch Excel.exe and open your workbook with OpenPyXL, such as 8.6_Open_me.xlsx, enabling editing and quick verification.
Take your finished course work into the real world by tackling a real-world Excel task and sharing feedback in the discussion forum to build confidence with more projects.
Requirements
Basic Python knowledge - Don't worry, we will cover each code snippet
You will need a computer with Python 3 installed, then we will cover how to install OpenPyXL
Some form of spreadsheet program. I use Excel, but you can also use OpenOffice or similar applications
Description
Become an Excel Power User - Learn how to control & automate Excel with Python and OpenPyXL
Do you have a bunch of Excel files that you need to format or put some value in a cell on each page? Do you need to create Charts on your spreadsheets or insert formulas? Maybe you just want to show off at the office! Whatever your needs, you can expect a comprehensive guide going through the nuts and bolts of how automating Excel works. The course dives straight into OpenPyXL, so you will be up and running creating and manipulating spreadsheets in no-time.
I have had so much use of OpenPyXL when dealing with spreadsheets. You can create advanced sorts and filters, insert and delete rows, copy cells, set custom formatting and much more. I even got a job based on my OpenPyXL knowledge. I am sure you will benefit from learning OpenPyXL if you have even the slightest interest in making your everyday life easier.
After taking this course you will:
Know how to create and manipulate Workbooks and Sheets
Read cell data with absolute and relative references
Iterate over cells and perform actions on each cell
Know how to delete rows and columns
Insert formulas and tables
Format your spreadsheets with fonts, colors and cell types
Understand how you could apply this knowledge to your own work
Create files and folders
Interact with open and save file dialogs
Whether it's gaming, business, engineering, or data you're passionate about, this course will give you everything you need for working on spreadsheets with Python. Take this course today, and begin your journey to having a full-fledged career as an Excel Power User!
Who this course is for:
Anyone interested in controlling and automating Excel with Python - with or without coding experience. People who want to get rid of manually editing hundreds of spreadsheets by hand
Especially suitable for those who would like to extract or add data on multiple spreadsheets or automate the creation of spreadsheets from input data
People who would like to know more about solving Excel problems with Python
People who would like to start consulting services by automating Excel tasks