Python | CSV and Excel exercise | Open a workbook of plants and find all the ones in stock
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
The above folder contains a workbook listing plants, some of which are not in stock:
The plants not in stock have the value No in column H (highlighted here in green).
Import the openpyxl module. Write a macro which starts on cell A2 and keeps going down until it hits a blank cell (ie one whose value is None). For each cell your macro should:
- Check the value of the cell offset 0 rows down and 7 columns to the right of the current one.
- If this is No your macro should print out this plant's name.
A typical output from your macro when it's finished might be something like this:
The openpyxl module tries to mimic Excel, but sometimes throws up warnings like this when it can't.
Close down your program, musing to yourself on whether it's really easier to do things like this in Python and not Excel!