Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 with hi, hello, how in first column's 3 cells.

sample code :-

import xlrd

workbook = xlrd.open_workbook('myfile.xls')
worksheet = workbook.sheet_by_name('Sheet1')
num_rows = worksheet.nrows - 1
curr_row = -1
while curr_row < num_rows:
        curr_row += 1
        row = worksheet.row(curr_row)
        print row

output :-

[text:u'hi']
[text:u'hello']
[text:u'how']

I want to read specific cell values from excelsheet, can someone suggest me if there is a way to do that?

like image 564
npatel Avatar asked Oct 20 '13 17:10

npatel


3 Answers

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)
like image 189
Cronje Fourie Avatar answered Oct 25 '22 23:10

Cronje Fourie


To access the value for a specific cell:

cell_value = worksheet.cell(row_number, column_number).value
like image 41
Bharath_Raja Avatar answered Oct 26 '22 00:10

Bharath_Raja


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

value = worksheet.cell(row, column)

like image 20
StvnW Avatar answered Oct 26 '22 00:10

StvnW