Instruction
Well done! Let summarize everything we've learned in this part:
- We can create a new workbook with the
Workbook()object and save its contents to a file with thesave()method:wb = Workbook() wb.save("Very important file.xlsx")Remember that if you choose a file name that's already in use,save()will overwrite the existing file. - Every workbook is created with one default worksheet named
"Sheet". - We can add new worksheets to a given workbook with the
create_sheet()method:wb.create_sheet("Second sheet") - To delete a worksheet, we can either use the
delkeyword:del wb["Second sheet"]
or theremove()method:wb.remove(wb["Second sheet"])
- Creating a copy of a given worksheet requires the
copy_worksheet()method. However:- We have to pass the worksheet we want to copy into the method:
ws = wb.active wb.copy_worksheet(ws)
- We cannot copy worksheets between different workbooks.
- We have to pass the worksheet we want to copy into the method:
- To change the value of a given cell, we can simply assign it data:
ws["A1"] = "13:00"
- If we want to append a whole row instead of modifying single cells, we can use the
append()method, passing the list of values as an argument:row = ["15:00", "Club meeting"] ws.append(row)
- We can delete rows and columns from our worksheet with the
delete_rows()ordelete_cols()methods, passing the row number or column index number as an argument:ws.delete_rows(3)
Before we try the final quiz for this course, let's do some review exercises!
Exercise
Click to continue.



