Created
November 2, 2018 14:46
-
-
Save lingmujianshi/7fce9843d169b65de9561fbf03dc9bfb to your computer and use it in GitHub Desktop.
スプレッドシートを使って翻訳
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Webページからデータを受けてスプレッドシートへ | |
function trans(data) { | |
var csv = data; | |
var array = toArray(csv); | |
writeToSheet(array); | |
} | |
//スプレッドシートへ書き込み | |
function writeToSheet(data) { | |
sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
//セルB2を先頭に配列の数だけシートにコピー | |
sheet.getRange(2,2,data.length,data[0].length).setValues(data); | |
//セルB3へ翻訳関数を書く | |
sheet.getRange(2,3).setValue('=GOOGLETRANSLATE(B2,"ja","en")'); | |
//翻訳関数を配列の数だけコピー | |
sheet.getRange(2,3).copyTo(sheet.getRange(3,3,data.length-2,1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function transBtn() { | |
function result(data){ | |
//ここに終わった後の処理を書く | |
} | |
//テキストボックスの内容を読み込む | |
value = document.getElementById("value").value; | |
//code.gs trans関数を実行し、結果が帰ってきたらresult関数を実行 | |
google.script.run.withSuccessHandler(result).trans(value); | |
} | |
</script> | |
<input type="button" value="変換" onClick="transBtn()"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment