-2
  1. The below code translates words that is located in the fruits.xlsx in Column A.
  2. I want the output/result should be in Column B
import xlrd
import goslate

loc = r"C:\path\fruits.xlsx"
gs = goslate.Goslate()

wb = xlrd.open_workbook(loc) 
sheet = wb.sheet_by_index(0)
  
for i in range(sheet.nrows): 
    print(gs.translate(sheet.cell_value(i, 0), 'de'))
    print(sheet.cell_value(i, 1)

I am receiving the below error

 return self._cell_values[rowx][colx]
IndexError: list index out of range

Please someone help me to write my output/result in the same excel in Column B

kumar
  • 5
  • 5

1 Answers1

0
for i in range(sheet.nrows - 1)

Python indicies begin from 0, so the last row will be sheet.nrows - 1

make sure to also add the closing parenthesis to the last print statement

print(sheet.cell_value(i, 1))
Seyi Daniel
  • 2,259
  • 2
  • 8
  • 18
  • this code is getting error `import xlrd import goslate loc = r"C:\path\fruits.xlsx" gs = goslate.Goslate() wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) for i in range(sheet.nrows - 1): print(gs.translate(sheet.cell_value(i, 0), 'de')) print(sheet.cell_value(i, 1)` Error is : `SyntaxError: unexpected EOF while parsing` – kumar Oct 06 '20 at 06:36
  • @kumar `print(sheet.cell_value(i, 1)` should be `print(sheet.cell_value(i, 1))` – Seyi Daniel Oct 06 '20 at 07:55