Locked lesson.
About this lesson
Tables are good for sorting data manually in your spreadsheet, and for drilling down and re-imagining your data.
Exercise files
Download this lesson’s related exercise files.
38 - Tables Part 1.docx57.5 KB 38 - Tables Part 1 SOLUTION.docx
56.2 KB
Quick reference
Tables Part 1
In this video I'll give you a short introduction to Tables.
When to use
Use this whenever you want to add a Table to your spreadsheet.
Instructions
We'll discuss how to create tables in the next video.
- Tables are good for sorting data manually in your spreadsheet.
- They're good for drilling down and re-imagining your data.
- 00:04 Okay, in this video I want to show you how to create tables with openpyxl.
- 00:07 And by tables I mean something like this where we have dropdowns and
- 00:10 we can sort by different things.
- 00:12 And we can change the data that's listed like that and things like that.
- 00:18 So that's what we're going to do in the next couple of videos.
- 00:22 Let's close this and let's create a new file.
- 00:24 Let's go File, New, and then let's go File Save As, and save this as table.py.
- 00:32 Now we need to import the same things we did earlier.
- 00:35 So from openpyxl.workbook we need to import our regular workbook.
- 00:44 We also need to from openpyxl import load_workbook so
- 00:50 that we can load our workbook.
- 00:53 And now we also need to import a couple of things that deal just with tables.
- 00:56 So let's go from openpyxl.worksheet.table,
- 01:03 that's a little bit new,
- 01:06 we need to import Table and TableStyleInfo.
- 01:12 So those are the two main table type things that we need.
- 01:14 So let's create our workbook like we've done before.
- 01:17 So let's set wb = Workbook, and this is a workbook instance.
- 01:22 And then we need to wb = load_workbook as we've done before.
- 01:28 And let's just use our company salaries xlsx file that we've been using throughout
- 01:32 this course.
- 01:33 So company_salaries.xlsx, and
- 01:38 then we need to set our active worksheet,
- 01:43 so ws = wb.active.
- 01:46 And then, eventually we're going to save this.
- 01:50 So let's wb.save it down here and let's save this as table.xlsx.
- 01:57 Okay, so let's look at our company salary xlsx file really quickly just to
- 02:01 familiarize ourselves with this.
- 02:03 So let's head over here, open this up.
- 02:05 And remember we created this third column, we don't actually need that for this.
- 02:09 So let's go ahead and get rid of it.
- 02:11 I'll just delete each of these things.
- 02:13 So remember we've got names and salaries, we've got all of our names and
- 02:18 then we've got this random salary data between 50 and $120,000.
- 02:22 So what we want to do is create a table out of this information.
- 02:25 So, okay, we've got our basic starter code here.
- 02:28 Now I think in the next video we'll jump in and actually create the table.
Lesson notes are only available for subscribers.