- I want to fix the below code, it should translate the words located in column A in the excel called "translation.xlsx", but it gives me an error
- Also it should give me the output/result(translated words) in the same excel(translation.xlsx") in column B.
code is here
import openpyxl
from googletrans import Translator
loc = r"C:\Users\userid\Desktop\translation.xlsx"
gs = Translator.translate()
wb = openpyxl.load_workbook(loc)
sheet = wb.active
for i in range(2, sheet.max_row + 1):
original = sheet.cell(row=i, column=1).value
translated = gs.translate(original, 'de')
sheet.cell(row=i, column=2).value = translated
wb.save(loc)
Error:
Traceback (most recent call last):
File "c:\Users\userid\translation.py", line 8, in <module>
gs = Translator.translate()
TypeError: translate() missing 2 required positional arguments: 'self' and 'text'
TypeError, not translation error. You wantgsto be instance ofTranslatorclass, so it has to begs = Translator()