0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【2025.07】GoogleスプレッドシートでDeepL翻訳を使う

Last updated at Posted at 2025-07-14

動機

以下のサイトの情報が古かったため。APIキー取得までは一緒。
https://jousys-force.deepapex.com/blogs/translate-using-deepl-on-spreadsheet

以下も参考にした。
https://qiita.com/chinotippy/items/d041627493cefb2f361d

Google Apps Scriptコード

  1. 以下のコードをGoogle Apps Scriptに貼り付け。
  2. Apps Scriptの画面で歯車「プロジェクトの設定」→「スクリプトプロパティ」に取得したDeepL APIキーをペースト。このとき、変数名をAPI_KEYに(以下のコードと対応)。
  3. 上書き保存。
  4. セル上でdeepl関数が使えるようになる。※日本語は"jp"ではなく"ja"
    例: =deepl("Hello World!", "en", "ja")
function deepl(text = 'こんにちは世界', sourceLanguage = 'ja', targetLanguage = 'en') {
  const key = PropertiesService.getScriptProperties().getProperty('API_KEY');
  //const key = '85a56460-879f-4241-871c-7cb074189dde:fx'
  const translatedText = 'https://api-free.deepl.com/v2/translate';
  const payloadData = {
    auth_key: key,
    text: text,
    target_lang: targetLanguage,
    source_lang: sourceLanguage
  };
  
  const params = {
    method: 'POST',
    contentType: 'application/x-www-form-urlencoded',
    payload: payloadData
  };
  
  const response = UrlFetchApp.fetch(translatedText, params);
  const json = response.getContentText(); 
  const data = JSON.parse(json); 
  const result = data.translations[0].text;
  return result;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?