简体   繁体   中英

how to make this translation function code by google apps-script?

I really want to add a translation menu on my google sheet but I definitely don't know what should I do at the last part.

function onOpen(e) {
SpreadsheetApp.getUi()
  .createMenu('Translation')
  .addItem('ko to eng', 'myFunction')
  .addToUi();
}
 var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveRange();
 var trans = LanguageApp.translate(sheet,'ko','en');

that is it for now. I want to make 'myFuncton' that can spread var 'trans' at the same place in the sheet. how can I code this?

If you'd like to print the translation eg on cells to the right of the selected cells, you can use this function:

function myFunction () {
  var range = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveRange();
  var trans = range.getValues().map(row => [LanguageApp.translate (row,'ko','en')])
 
  range.offset(0,1).setValues(trans)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM