Skip to content Skip to sidebar Skip to footer

Reading Particular Cell Value From Excelsheet In Python

I want to get particular cell values from excelsheet in my python script. I came across xlrd, xlwt, xlutils modules for reading/writing to/from excelsheet. I created myfile.xls wit

Solution 1:

To access the value for a specific cell you would use:

value = worksheet.cell(row, column)

Solution 2:

To access the value for a specific cell:

cell_value = worksheet.cell(row_number, column_number).value

Solution 3:

This code is to select certain cells from Excel using Python:

import openpyxl

wb = openpyxl.load_workbook(r'c:*specific destination of file*.xlsx')
sheet = wb.active
x1 = sheet['B3'].value
x2 = sheet['B4'].value
y1 = sheet['C3'].value
y2 = sheet['C4'].value
print(x1,x2,y1,y2)

Solution 4:

The code below will help you in solving the problem:

worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
curr_row = 0while curr_row < num_rows:
        curr_row += 1
        row = worksheet.row(curr_row)
        print row[0].value

Solution 5:

Code snippet for reading xlsx file in python using xlrd

import xlrd

def readdata():
    workbook = xlrd.open_workbook("src.xlsx", "rb")
    sheets = workbook.sheet_names()
    for sheet_name in sheets:
        sh = workbook.sheet_by_name(sheet_name)
        for rownum in range(1, sh.nrows): #skipping header of the xlsx
           print(sh.cell(rownum, 2)) # e.g Printing all rows value of 3rd column

readdata()

if any error 'No Module found xlrd'. Install xlrd using below command in terminal

pip install xlrd

Post a Comment for "Reading Particular Cell Value From Excelsheet In Python"