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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Search Student Records in Excel Using Python xlrd

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

data-processingExcelSearchxlrd
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.