
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 openpyxl and Python, explore the OpenPyXL documentation to understand what it covers and where to find it, and always back up your data to prevent data loss.
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.
Explore OpenPyXL documentation to learn how the worksheet module works, discover constants, and review the source code to understand how OpenPyXL handles Excel tasks.
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.
Open an existing workbook with OpenPyXL by using load_workbook on 2.1_Hello_world.xlsx, inspect the sheets by iterating wb and printing each sheet.title, and save the workbook when changes are made.
Learn to create, rename, delete, and save sheets in OpenPyXL by manipulating workbooks and worksheets, including inserting at position zero and appending new sheets to the workbook.
Copy sheets in OpenPyXL by loading a workbook, selecting a source sheet, using wb.copy_worksheet to duplicate it, renaming the new sheet, and saving to copied_sheets.xlsx.
Learn how to access Excel sheets with Python using openpyxl by index or by name, load workbooks, check sheet names, and handle missing sheets with KeyError.
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.
Explore how to use openpyxl's offset method to reference adjacent cells, set values with ws.cell, and work with relative and absolute references in practical examples.
Learn how openpyxl creates and iterates over cell ranges, using relative and absolute referencing, printing values from A1 to C2, and using get_column_letter to reference columns.
Learn to iterate over cells using OpenPyXL, leveraging built-in iter_row and iter_col to simplify looping, and determine the spreadsheet size with max_row and max_column.
Loop through rows and columns in OpenPyXL using iterators and range, then print cell coordinates like A1 through C1 to navigate a worksheet.
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.
Apply openpyxl's append method to add headers and data rows to the end of a spreadsheet, using a sales and years example.
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.
Learn to insert an Excel table with openpyxl by creating a sales table from A1:C5, applying table style medium 9, enabling row stripes, and adding the table to the worksheet.
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 use freeze panes in OpenPyXL to keep top rows or left columns visible while scrolling by setting the freeze panes reference (A2, B1, C1) or unfreezing.
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 how to create files and folders with Python using os and OpenPyXL, write to text files, read lines, and create directories with error handling.
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