The translation result should be in Column B in the same excel sheet (fruits.xlsx)

60 Views Asked by At
  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

1

There are 1 best solutions below

2
On
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))