免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
javascript – Google Apps中用于多個(gè)查找和替換的Google Apps腳本

關(guān)于Stack Exchange的第一個(gè)問題,所以希望它有意義.

一些背景:我在學(xué)校環(huán)境中工作,并協(xié)助學(xué)習(xí)支持人員為某些學(xué)生創(chuàng)建更可讀的時(shí)間表.

他們正在復(fù)制我們網(wǎng)站的時(shí)間表數(shù)據(jù),其中包含主題代碼,教師姓名和房間號碼.它與您在下圖中看到的格式完全相同 – 我只是將其復(fù)制到Google表格中.

我基本上需要對所有這些代碼執(zhí)行批量查找和替換,并完全展開它們以便例如主題代碼. 01ENG02成為“英語”和教師代碼,例如JBO成為“Joe Bloggs”

我有一個(gè)完整的列表,我需要擴(kuò)展到的代碼 – 它是如何最好地實(shí)現(xiàn)它.

以下是我在Stack Exchange和我正在使用的其他網(wǎng)站上找到的一些Google Scripts代碼:

function runReplaceInSheet(){  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("StudentTimetableEntry");  // Replace Subject Names  replaceInSheet(sheet, /\d\dART\d\d/g, "Art");  replaceInSheet(sheet, /\d\dCCL\d\d/g, "Communication & Culture");  replaceInSheet(sheet, /\d\dDLT\d\d/g, "Digital Technology");  replaceInSheet(sheet, /\d\dDRA\d\d/g, "Drama");  // Replace Staff Names    replaceInSheet(sheet, 'TED', 'Tahlee Edward');  replaceInSheet(sheet, 'TLL', 'Tyrone LLoyd');  replaceInSheet(sheet, 'TMA', 'Timothy Mahone');  replaceInSheet(sheet, 'TQU', 'Tom Quebec');}function replaceInSheet(sheet, to_replace, replace_with) {  //get the current data range values as an array  var values = sheet.getDataRange().getValues();  //loop over the rows in the array  for (var row in values) {    //use Array.map to execute a replace call on each of the cells in the row.    var replaced_values = values[row].map(function(original_value) {      return original_value.toString().replace(to_replace, replace_with);    });    //replace the original row values with the replaced values    values[row] = replaced_values;  }  //write the updated values to the sheet  sheet.getDataRange().setValues(values);}

這非常有效.但是,我有超過150個(gè)員工名稱,并且主題代碼的數(shù)量大致相同.這個(gè)過程達(dá)到了最長時(shí)間,我確信必須有一個(gè)更好的編碼方式.

我會(huì)考慮其他方法,但請記住,對于將要使用它的員工來說,它需要盡可能簡單明了.

解決方法:

每次在腳本中調(diào)用getValues和setValues時(shí),都會(huì)產(chǎn)生相當(dāng)大的開銷成本并降低腳本速度. (Google app script timeout ~ 5 minutes?)我修改了你的上面的腳本,以便為getValues和1調(diào)用setValues進(jìn)行1次調(diào)用.在將修改后的時(shí)間表粘貼回工作表之前,代碼將所有替換應(yīng)用于內(nèi)存中的數(shù)組.

function runReplaceInSheet(){  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("StudentTimetableEntry");  //  get the current data range values as an array  //  Fewer calls to access the sheet -> lower overhead   var values = sheet.getDataRange().getValues();    // Replace Subject Names  replaceInSheet(values, /\d\dART\d\d/g, "Art");  replaceInSheet(values, /\d\dCCL\d\d/g, "Communication & Culture");  replaceInSheet(values, /\d\dDLT\d\d/g, "Digital Technology");  replaceInSheet(values, /\d\dDRA\d\d/g, "Drama");  // Replace Staff Names  replaceInSheet(values, 'TED', 'Tahlee Edward');  replaceInSheet(values, 'TLL', 'Tyrone LLoyd');  replaceInSheet(values, 'TMA', 'Timothy Mahone');  replaceInSheet(values, 'TQU', 'Tom Quebec');  // Write all updated values to the sheet, at once  sheet.getDataRange().setValues(values);}function replaceInSheet(values, to_replace, replace_with) {  //loop over the rows in the array  for(var row in values){    //use Array.map to execute a replace call on each of the cells in the row.    var replaced_values = values[row].map(function(original_value) {      return original_value.toString().replace(to_replace,replace_with);    });    //replace the original row values with the replaced values    values[row] = replaced_values;  }}

嘗試使用此代碼,如果仍有超時(shí)問題,我的建議是設(shè)置觸發(fā)器以幫助鏈功能.

來源:https://www.icode9.com/content-1-480651.html
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
python操作Excel讀寫--使用xlrd
xlrd首頁、文檔和下載
Excel 如何按某一列的數(shù)字插入行
python創(chuàng)建excel文件,并進(jìn)行讀與存操作
python操作Excel的幾種方式
Python自動(dòng)化辦公Excel模塊openpyxl原理及用法解析
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服