[英]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.