【问题标题】:Python Translation from excel fileexcel文件中的Python翻译
【发布时间】:2021-01-11 23:51:21
【问题描述】:

我想翻译存储在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)

【问题讨论】:

    标签: python xlrd goslate


    【解决方案1】:
    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'))
    

    【讨论】:

    • 如何将结果写入excel表格的B列
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 2011-11-28
    • 1970-01-01
    相关资源
    最近更新 更多