Creating new sheets in an Excel spreadsheet
In this recipe, we'll demonstrate how to create a new Excel spreadsheet from scratch and deal with multiple sheets within that spreadsheet, including creating them.
Getting ready
We will use the openpyxl
module. We should install the module, adding it to our requirements.txt
file as follows:
$ echo "openpyxl==3.0.3" >> requirements.txt
$ pip install -r requirements.txt
We'll store it in the new file information about the movies with the most attendance. The data is extracted from here: http://www.mrob.com/pub/film-video/topadj.html.
How to do it...
- Import the
openpyxl
module:>>> import openpyxl
- Create a new Excel file. This creates a default sheet, called
Sheet
:>>> xlsfile = openpyxl.Workbook() >>> xlsfile.sheetnames ['Sheet'] >>> sheet = xlsfile['Sheet']
- Add data about the number...