Let's summarize what we have learned so far.
We have learned how to create and open workbooks.
We have learned how to add and remove sheets how to rename them and also how to access them by index
or name.
So let's do a small recap here.
First we start by from openpyxl
We import the load workbook and also workbook and then we want to load a worksheet.
So let's say wb let's make this wb to open the load work book and let's make this from our earlier
examples hello copies.xlsx and let's also create a new workbook.
So we need to do it like this and remember the parent is this and let's say that we now want to add
a sheet to our work workbook.
So we do wb.create_sheet and fresh new sheet and we insert it at position 1 and also now you
can see that we have created it.
So let's print it out so that we can see that it's actually created, print sheet
dot title
Okay.
And now maybe we want to delete a sheet so let's then go and take.
Wb.remove and wb
sheet
and let's now then take that it was actually removed and we say that we have removed sheet what do we
want to do next.
Maybe we want to create a copy then so we can create a copy from source equals wb a fresh new sheet
and then we set the new sheet to be a wb.copy sheet and we pass the sheet that we created which
is the source or that we created which is the source.
know workbook object has no copy sheet because it's actually copy worksheet.
So remember to check the documentation.
So we have copy worksheet and then we can give our new sheet a name.
So a copy
And then again let's see what we get.
And we have a copy, and you saw now that I accessed all the sheets by name.
So let's see if we can do this by getting the sheet names and indexes.
So as you can see on the side here we have made a function to get all the sheet names but we can also
do like this and use the enumerate function here.
So let's say for index sheet in enumerate wb:
And then we want to return or we want to print actually index.
And sheet.title to make it a bit easier.
So then we see that index zero has a fresh new sheet and index 1 has a copy and then we can access them
with wb.worksheets 0 dot title and that's it for 1.
And we can also do this for wb2, let's see what it was hello or do we have a third worksheet.
Yes.
I doubt we have a fourth in it.
Yeah.
List index out of range so we know it's only three sheets in the wb2 workbook.
What do we want to do then.
That's pretty much it.
I would say for this, so and again if you forget anything of this the methods what they are called
go and visit the documentation at openpyxl.readthedocs.io
That's it for this lesson.