2016-10-07 18 views
0
  1. 我想所有的非空單元A/B從片材「合併表單」複製在列,然後將這些細胞貼到片材「輸入對於Web應用程序「到列H:我(始終從頂部開始,而不是將它們作爲新行添加,因爲這些值將不斷更新)。複製非空範圍到新的片材,然後向下拖動式

  2. 然後,我基本上想要將其他列中的所有公式(A到G)一直拖到粘貼的最後一行。

  3. 格式欄I作爲日期。

我不確定是否需要循環來做這個或只是一個數組。我已經嘗試了這兩種方式,但不斷收到錯誤。

選項1:在這裏,我得到這個錯誤:

TypeError: (class)@2e3b19c is not a function, it is object.

function copynotempty(){ 
    var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CONSOLIDATION SHEET"); 
    var col = 0 ; // choose the column you want to check: 0 = col A, 1= col B ... 
    var lastrow = ss.getLastRow(); 
    var range = ss.getRange(5,1,lastrow-4,2); 
    var values=range.getValues();// data is a 2D array, index0 = col A 
    var formulas=range.getFormulas();// data is a 2D array, index0 = col A 
    var target= new Array();// this is a new array to collect data 
    //for(n=0;n<range.getHeight();++n){ 
    if (values()!=''|| formulas()!=''){ ; (
      var sh2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Inputs for Web App"); //target sheet of the spreadsheet 
      range.copyTo(sh2.getRange(4,8,range.height,range[0].length),{contentsOnly:true}); 
       } 
      } 

選項2:在這裏,我不斷收到此錯誤:

"TypeError: Cannot set property "0.0" of undefined to "(VALUE OF CELL)"

function copynotempty(){ 
    var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CONSOLIDATION SHEET"); 
    var col = 0 ; // choose the column you want to check: 0 = col A, 1= col B ... 
    var lastrow = ss.getLastRow(); 
    var range = ss.getRange(5,1,lastrow-4,2); 
    var values=range.getValues();// data is a 2D array, index0 = col A 
    var formulas=range.getFormulas();// data is a 2D array, index0 = col A 
    var target= new Array();// this is a new array to collect data 
for(n=0;n<range.getHeight();++n){ 
    if (values[n][col]!=''|| formulas[n][col]!=''){ ; 
     for (cc=0;cc<range.getWidth();++cc){ 
       if (values[n][cc]!=''){target[n][cc]=values[n][cc]} // if the cell has a value, copy it 
       } 
       } 
      } 
      if(target.length>0){// if there is something to copy 
       var sh2=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Inputs for Web App"); //second sheet of your spreadsheet 
      sh2.getRange(4,8,target.height,target[0].length).setValues();// paste the selected values in the 2cond sheet 
      } 
     } 
+0

你能舉幾個例子數據嗎? –

回答

1

在第一個功能你的問題是您嘗試撥打values()formulas(),這兩個字符串都是二維數組。

移動過來的數據(這是目前你正試圖在功能,唯一要做的事情),可以做這樣的:

function copynotempty(){ 
    var ss = SpreadsheetApp 
     .getActiveSpreadsheet() 
     .getSheetByName("CONSOLIDATION SHEET"); 

    var lastrow = ss.getLastRow(); 
    var range = ss.getRange(5,1,lastrow-4,2); 

    var nonEmpty = range 
     .getValues() 
     .filter(function(row) {   // filter matrix for rows 
     return row.some(function(col) { // that have at least one column 
      return col !== "";});});  // that is not empty 

    if (nonEmpty) { 
    var sh2=SpreadsheetApp 
     .getActiveSpreadsheet() 
     .getSheetByName("Inputs for Web App"); 

    sh2.getRange(4,8, nonEmpty.length, nonEmpty[0].length) 
     .setValues(nonEmpty); 
    } 
} 
  • 可這也許是用數組公式解決?
  • 這可能是最好的通過設置列格式爲您選擇的dtae格式,或者你想要一個字符串?
  • 相關問題