function importrange(fromSheetd,fromRange,toSheetd,toRange) {
let fromSheet = SpreadsheetApp.openByUrl(fromSheetd)
let toSheet = SpreadsheetApp.openByUrl(toSheetd)
let fromSheetName = fromRange.split("!")[0]
let fromSheetRange = fromRange.split("!")[1]
let fromDataSheet = fromSheet.getSheetByName(fromSheetName)
let fromData = fromDataSheet.getRange(fromSheetRange).getValues()
let toSheetName = toRange.split("!")[0]
let toSheetRange = toRange.split("!")[1]
let toDataSheet = toSheet.getSheetByName(toSheetName)
toDataSheet.getRange(toSheetRange).setValues(fromData)
return 1
}
function importrangebyid(fromSheetd,fromRange,toSheetd,toRange) {
let fromSheet = SpreadsheetApp.openById(fromSheetd)
let toSheet = SpreadsheetApp.openById(toSheetd)
let fromSheetName = fromRange.split("!")[0]
let fromSheetRange = fromRange.split("!")[1]
let fromDataSheet = fromSheet.getSheetByName(fromSheetName)
let fromData = fromDataSheet.getRange(fromSheetRange).getValues()
let toSheetName = toRange.split("!")[0]
let toSheetRange = toRange.split("!")[1]
let toDataSheet = toSheet.getSheetByName(toSheetName)
toDataSheet.getRange(toSheetRange).setValues(fromData)
return 1
}
function importRangeCore() {
let ss = SpreadsheetApp.getActiveSpreadsheet()
let sheet = ss.getSheetByName("Core")
let last = sheet.getLastRow() - 1
let data = sheet.getRange(2,1,last,4).getValues()
data.filter(function(value){
if (value[0]) {
try {
importrange(value[0],value[1],value[2],value[3])
} catch(e) {
Logger.log(e)
}
}
})
}
function doGet(e){
var params = e.parameter
var fromSheet = params.fs;
var fromRange = params.fr
var toSheet = params.ts
var toRange = params.tr
if (importrangebyid(fromSheet,fromRange,toSheet,toRange))
{
return HtmlService.createHtmlOutput("Import Complete")
}
return HtmlService.createHtmlOutput("Error")
};
No comments:
Post a Comment
THANKS FOR YOUR SUPPORT