Locked lesson.
About this lesson
In this lesson, we'll build a Table.
Exercise files
Download this lesson’s related exercise files.
39 - Tables Part 2.docx57.4 KB 39 - Tables Part 2 SOLUTION.docx
58.1 KB
Quick reference
Tables - Part 2
In this video we'll build a Table.
When to use
Use this whenever you want to use a Table in your spreadsheet.
Instructions
# Import libraries:
from openpyxl.worksheet.table import Table, TableStyleInfo
# Create a Table instance
tab = Table(displayName="Our Table", ref='A1:B6')
# Define the Table Style
style = TableStyleInfo(
name = "TableStyleMedium9",
showFirstColumn = False,
showLastColumn = False,
showRowStripes = True,
showColumnStripes = True,
)
# Set defined Style
tab.tableStyleInfo = style
# Add the table to the worksheet
ws.add_table(tab)
Hints & tips
- from openpyxl.worksheet.table import Table, TableStyleInfo
- tab = Table(displayName="Our Table", ref='A1:B6')
- style = TableStyleInfo(name = "TableStyleMedium9", showFirstColumn = False, showLastColumn = False, showRowStripes = True, showColumnStripes = True,)
- tab.tableStyleInfo = style
- ws.add_table(tab)
Lesson notes are only available for subscribers.