Python Excelファイルを読込みGoogleTranslateを使ってみた


目的

 私は仕事で海外の特許調査をする機会が過去にあったんですが、海外の特許調査なので当然親切に日本語に翻訳してくれてなんかいない!中国語やら英語やら・・・語学力の無い私はGoogle翻訳で検索→翻訳を実施して特許の内容を理解しなければならない。この翻訳作業を少しでも軽減できないか?と考え、本ツールを作成するに至った。

環境

Windows10 Home 64bit
Python3.8.3

Toolの概要

 調査する特許はExcelファイル形式の為、英語or中国語で記載された列の文章を読込み、その隣の列に日本語の翻訳結果を出力する事にした。

必要なライブラリー

以下を事前にインストールしてください。

pip install openpyxl
pip install googletrans

コード

main.py
from googletrans import Translator
import openpyxl as excel

#Excelファイルの指定
test_file = excel.load_workbook("<filepath>",data_only=True)
#Sheetの選択
sheet = test_file.worksheets[0]
#excelの最終行を取得
max_row = sheet.max_row

translator = Translator()

for i in range(1,max_row+1):
    bf_trans = sheet.cell(row=i,column=1).value
    trans_text = translator.translate(bf_trans,dest='ja')
    sheet.cell(row=i,column=2).value = str(trans_text.text)

#excelファイルを閉じて終了
test_file.save("<filepath>")

最後に

翻訳結果みると・・・微妙な文もあるが、少しは役にたつかな~。