[英]How to combine two functions google-app-script?
我是应用程序脚本的新手,并试图为同一张表组合两个函数,这是我正在使用的函数:
function cpydata() {
ImportRange(
"1dZuOYi75xJTqQSpssmI7jQ8i6_J3I7DduoCQR9MVFM0",
"Prospect Form!J2:T","1w5akaeADH-S9pBgCKLKltYhUntSIDUxwZkWPT0WPg_k",
"BOB!A2"
);
};
function ImportRange(sourceID,sourceRange,destinationID,destinationRangeStart) {
const sourceSS = SpreadsheetApp.openById(sourceID);
const sourceRng = sourceSS.getRange(sourceRange);
const sourceVals = sourceRng.getValues();
console.log(sourceVals);
};
function clear() {
var
sheet = SpreadsheetApp.getActive().getSheetByName('Prospect Form');
sheet.getRange('C26:C28').clearContent()
sheet.getRange('F3:F219').clearContent()
sheet.getRange('G211:G219').clearContent()
sheet.getRange('F221:F225').clearContent();
}
它正在清除单元格,但是,复制数据功能不起作用。我做错了什么?
在您的评论中,您说您想将某个范围从源电子表格(表格“前景表格”)复制到某个目标电子表格(表格“BOB”)并清除源表格中的数据。 如果您不需要保留原始格式,可以通过以下方式完成:
function copy_range_without_formatting() {
var src_id = "1OqSv464lZ0mLsN9jApjf5Ub4MHMzBz9flw7217yYmRc";
var src_range_str = "Prospect Form!J2:T";
var dest_id = "1Kv8la3Yf8N9QB0sI-MnMc-C2zCYAKJuGiP5v_JnWlcA";
var dest_range_str = "BOB!A2";
// get the source range
var src_range = SpreadsheetApp.openById(src_id)
.getSheetByName(src_range_str.split('!')[0]) // get the sheet 'Prospect Form'
.getRange(src_range_str.split('!')[1]); // get the range 'J2:T'
// get values from the source range
var values = src_range.getValues();
// clear the source range
src_range.clear();
// copy the values to the destination sheet
SpreadsheetApp.openById(dest_id)
.getSheetByName(dest_range_str.split('!')[0]) // get the sheet 'BOB'
.getRange(2,1,values.length,values[0].length) // '2,1' = 'A2'
.setValues(values);
}
如果要保留原始格式,则需要更复杂的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.