January 2019
Beginner
318 pages
8h 23m
English
In this section, we are going to read multiple cells. We will use the openpyxl module. Create a script called read_multiple.py and write the following content in it:
import openpyxlbook_obj = openpyxl.load_workbook('sample.xlsx')excel_sheet = book_obj.activecells = excel_sheet['A1': 'C6']for c1, c2, c3 in cells: print("{0:6} {1:6} {2:6}".format(c1.value, c2.value, c3.value))
Run the script and you will get the following output:
student@ubuntu:~/work$ python3 read_multiple.py
Following is the output:
Id First Name Last Name 101 John Smith 102 Mary Williams 103 Rakesh Sharma 104 Amit Roy 105 Sandra Ace
In the preceding example, we are reading the data of three columns by using the range operation. Then, we read the ...
Read now
Unlock full access