How to Search Student Records in Excel Using Python xlrd
This tutorial demonstrates how to use Python's xlrd library to read an Excel file containing student records and retrieve a specific student's information by name or ID, covering installation, code walkthrough, and sample output.
I have an Excel spreadsheet that records student information, and I want to query a student's details by their name or student ID.
First, install the required third‑party library: C:\Users\Administrator>pip install xlrd Then use the following Python code:
import xlrd
file = "info.xlsx"
name = input("Pleas enter name:")
workbook = xlrd.open_workbook(file)
Table = workbook.sheet_by_name("Sheet1") # alternatively: Table = workbook.sheet_by_index(0)
length = Table.nrows
for i in range(length):
row = Table.row_values(i)
if name in row[0]:
print(row[0:6])The script opens the Excel file, accesses the first sheet, iterates over each row, and prints the full row when the entered name matches the first column (the student's name).
Sample output when searching for "李四":
['李四', 'HY1232', '男', 18.0, 52364178932.0, 95.0]This result is displayed in the console after the user inputs the desired name.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
