翻訳(日本語⇒英語)
英語に翻訳し別のワークブックとして保存します
翻訳にはgoogletransのTranslatorを用います
コード
import datetime
import openpyxl
from googletrans import Translator
translator = Translator()
workBook = openpyxl.load_workbook(“travel_schedule.xlsx”)
sheet = workBook.active
for row in sheet:
for cell in row:
#空白セル処理
if cell.value is None:
continue
#数値処理
if isinstance(cell.value,int):
continue
#時刻処理
if isinstance(cell.value,datetime.time):
cell.number_format = “h:mm”
continue
#日付処理
if isinstance(cell.value,datetime.datetime):
cell.number_format = “yyyy/m/d”
continue
cell.value = translator.translate(str(cell.value), dest=”en”).text
workBook.save(“translate.xlsx”) #保存
日本語
旅行スケジュール 2020/8/1
時刻 場所 内容
7:00 東京駅 広島行きの新幹線に乗車します
11:00 広島駅 駅ビル周辺を散策
11:30 広島駅 昼食はお好み焼き
12:30 広島駅 バスで宮島へ移動
13:30 フェリー乗り場 フェリーで宮島へ移動
13:40 宮島 自由時間
17:30 ホテル ホテルに集合
19:00 ホテル 夕食
英語翻訳
Travel schedule 2020/8/1
time place content
7:00 Tokyo Station Take the Shinkansen bound for Hiroshima
11:00 Hiroshima station Take a walk around the station building
11:30 Hiroshima station Okonomiyaki for lunch
12:30 Hiroshima station Transfer to Miyajima by bus
13:30 ferry station Transfer to Miyajima by ferry
13:40 Miyajima free time
17:30 Hotel Meet at the hotel
19:00 Hotel dinner
この記事へのコメントはありません。