From the course: Rapid Application Development with Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Accessing Excel files with openpyxl

Accessing Excel files with openpyxl - Python Tutorial

From the course: Rapid Application Development with Python

Start my 1-month free trial

Accessing Excel files with openpyxl

- [Instructor] Let's take a first look at the openpyxl library using Windows Visual Studio code. In the exercise folder, you'll find the spreadsheet that we'll use: CSF-Audit.xlsx. I have code open at the terminal window, so I'll start up Python. And we need to import the openpyxl library, so I'll type import openpyxl, and then we need to load the workbook called CSF-Audit.xlsx into openpyxl. We'll use the forward slash rather than the normal backwards slash for this to avoid unicode escape sequence conflicts. wb=openpyxl.load_workbook('c:/python/CSF-Audit.xlsx'). Okay, we can now reference the workbook using wb. We can list the sheets by simply entering wb.sheetnames. And we can get a handle to the first sheet by indexing with the sheet name: ws=wb['Template']. Now we have an active sheet. We can retrieve the contents of a cell by simply referencing the value in the cell location. Let's retrieve the first CSF…

Contents