Function to pick a row from an Excel table and slice

Asked

Viewed 75 times

1

You can take a row from the table and divide it into as many pieces as you want?

I can take cell by cell from the table using an approach I learned here on the forum in an already answered question, but I think I’m opening the same file 2,000 times.

Is it possible, gentlemen?

Here’s the implementation I use today:

workbook = xlrd.open_workbook('MONITORA.xlsm')
worksheet = workbook.sheet_by_name('PREÇO')
preço = worksheet.cell(0, 1)
preço_dois = worksheet.cell(0, 2)
  • The library used was the xlrd? It would be interesting to include the question and the answer to help those who come here to search later.

  • I was going to, but I needed to get a higher score

1 answer

2

I managed to do using this code

excel_sheet = xlrd.open_workbook('MONITORA.xlsm')
sheet1 = excel_sheet.sheet_by_name('PREÇO')
row = sheet1.row(0)  # 1st row

for i in range(0, sheet1.nrows):
    row = sheet1.row_slice(i)
    Gname = row[0].value
    Fname = row[1].value
    Lname = row[2].value

    print (Gname)
    print (Fname)
    print (Lname)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.