[英]Google App Script - Custom Importrange Function, Need Auto-Update
我正在將數據從9個不同的Google表格移植到主概覽面板,以跟蹤公司指標。 我沒有使用ImportRange,而是使用Google Apps腳本創建了一個自定義函數,因為我需要所有格式設置。 我要復制的工作表使用公式,因此我首先在沒有公式的源電子表格中創建工作表的副本,然后將該工作表復制到目標電子表格中。
ImportRange的好處是它會不斷獲取數據並自動更新。 我在下面編寫的函數會創建和刪除工作表,以將格式移植到masterSS上。 是否有解決方法,任何人都可以想到僅獲取值即可自動更新,而無需創建和刪除一堆新工作表?
另外,每次創建和刪除新工作表時,工作表計數都會增加1。是否可以重置此計數器?
function importPortComp(portComp, srcRange, destRange) {
// Create temporary sheet in source spreadsheet
var tempSheet = portComp.insertSheet();
// Copy values, formatting, and column widths to temporary sheet
srcRange.copyTo(tempSheet.getRange(1, 1), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
srcRange.copyTo(tempSheet.getRange(1, 1), SpreadsheetApp.CopyPasteType.PASTE_FORMAT, false);
srcRange.copyTo(tempSheet.getRange(1, 1), SpreadsheetApp.CopyPasteType.PASTE_COLUMN_WIDTHS, false);
// Copy temporary sheet destination spreadsheet
var copiedSheet = tempSheet.copyTo(masterSS);
// Delete temporary sheet from source spreadsheet
portComp.deleteSheet(tempSheet);
// Copy source range to destination range
copiedSheet.getRange(srcRange.getA1Notation()).copyTo(destRange);
copiedSheet.getRange(srcRange.getA1Notation()).copyTo(destRange, SpreadsheetApp.CopyPasteType.PASTE_COLUMN_WIDTHS, false);
// Delete copied sheet from T/R spreadsheet
masterSS.deleteSheet(copiedSheet);
}
如果我正確理解您的問題,請使用:
array = sheet.getSheetValues(startRow, startColumn, numRows, numColumns)
要獲取值,然后以正確的索引(我想是array[row][column]
)將其壓入數組。要“ concat / add”的其他數據設置了正確的范圍和用法
sheet.range.setValues(array)
您可以查看此文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.