0

我想翻译存储在 A 列的 excel 文件中的单词

我有 2 部分代码(如下所述的第 1 部分和第 2 部分),我不知道如何合并这两个代码以将每个单词成功翻译到 B 列。

寻求您的帮助

读取 Excel 文件:第 1 部分的代码

import xlrd


 # Give the location of the file 
loc = (r"path\fruits.xlsx") 
  
# To open Workbook 
wb = xlrd.open_workbook(loc) 
sheet = wb.sheet_by_index(0) 
sheet.cell_value(0, 0) 
  
for i in range(sheet.nrows): 
    print(sheet.cell_value(i, 0))

翻译:第 2 部分的代码

import goslate

text = "i am coming tomorrow"

gs = goslate.Goslate()
translatedText = gs.translate(text, 'de')

print(translatedText)
4

1 回答 1

0
import xlrd
import goslate

loc = r"C:\Users\kumarant\Desktop\Django\sahil\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'))
于 2020-09-25T16:05:51.000 回答