I'm trying to extract only a particular number of rows from the an excel sheet. I'm able to provide the start, but I don't know how to include the stop value for the row. I haven't been able to find anything in the documentation that can help me with the stop.
workbook = xlrd.open_workbook(path)
worksheet = workbook.sheet_by_name('sheet1')
for row in range(0,worksheet.nrows):
print(row)
I get 1 to 250, which is the end of the spreadsheet. I want to be able to extract only 1 to 125. How do I specify that end?
I tried:
for row in range(0,125,worksheet.nrows):
print(row)
I got 0 0 0 0
How do I get 1,2,3...125?
I using tried the solution here:
worksheet.row_values(0, 0 , 125) for row
But I get a syntax error.
All the other answers I found in SO use worksheet.nrows which goes all the way to the end I only want it to go to 125.
print(sheet.row_values(row_number))
# Program to extract a particular row value
import xlrd
loc = ("path of file")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
print(sheet.row_values(1))
Acc To Your code:
for index in range(0,125):
print(sheet.row_values(index))