Locked lesson.
About this lesson
To work with workbooks and worksheets in excel, we need to import some things from openpyxl.
Exercise files
Download this lesson’s related exercise files.
13 - Creating Workbooks and Worksheets.docx57.2 KB 13 - Creating Workbooks and Worksheets SOLUTION.docx
57.6 KB
Quick reference
Creating Workbooks and Worksheets
To work with workbooks and worksheets in excel, we need to import some things from openpyxl.
When to use
Do this anytime you want to work with an Excel spreadsheet in Python.
Instructions
from openpyxl.workbook import Workbook
# Create a workbook instance
wb = Workbook()
# Set an active worksheet
ws = ws.active
# Create another worksheet
work_sheet1 = wb.create_sheet('New Sheet 1')
# Set a title to active sheet
ws.title = "Our Active Worksheet"
# Print out sheet names
print(wb.sheetnames)
Hints & tips
- from openpyxl.workbook import Workbook
- wb = Workbook()
- ws = ws.active
- work_sheet1 = wb.create_sheet('New Sheet 1')
- ws.title = "Our Active Worksheet"
- print(wb.sheetnames)
Lesson notes are only available for subscribers.