簡體   English   中英

Google Apps腳本-在電子表格中查找列的最后一個空行

[英]Google Apps Script - Find Last Empty Row of a Column in Spreadsheet

我目前有一個像這樣的腳本:(哪個將每分鍾運行並獲取任何值)

  // function 01
  sheet2.getRange(sheet2.getLastRow() + 1, 1, 1, 6).setValues(values);

  // function 02
  sheet2.getRange(sheet2.getLastRow() + 1, 10, 1, 6).setValues(values);

它找到最后一行並在下一行中設置值。 兩者都有各自的功能。 但是目前它輸出的是這樣的東西。

電流輸出:不佳

// function 1 output here       // function 2 output here
------------------------------------------------------------
|   A    |     B    |   C     ||         |         |        |
------------------------------------------------------------
|        |          |         ||   D     |    E    |   F    |
------------------------------------------------------------
|        |          |         ||   G     |    H    |   I    |
------------------------------------------------------------
|   J    |    K     |   L     ||         |         |        |
------------------------------------------------------------

我希望這樣顯示:

預期結果

------------------------------------------------------------
|   A    |     B    |   C     ||   D     |    E    |   F    |
------------------------------------------------------------
|   J    |     K    |    L    ||   G     |    H    |   I    |
------------------------------------------------------------
|        |          |         ||         |         |        |
------------------------------------------------------------

希望我明白。

嘗試下面的功能,對其進行了稍微修改,以響應2014年11月27日為新圖紙提供的解決方案Mogsdad中的列,以響應線程更快的方法以查找第一個空行

// Don's array approach - checks first column only
// With added stopping condition & correct result.
// From answer https://stackoverflow.com/a/9102463/1677912
// Added the passing of myColumn which needs to be a column range
// example use: var emptyRow = getFirstEmptyRowByColumnArray('B:B');
function getFirstEmptyRowByColumnArray(myColumn) {
  var spr = SpreadsheetApp.getActiveSpreadsheet();
  var column = spr.getRange(myColumn);
  var values = column.getValues(); // get all data in one call
  var ct = 0;
  while ( values[ct] && values[ct][0] != "" ) {
    ct++;
  }
  return (ct+1);
}

當然,也可以編寫它以僅通過該列並根據需要創建范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM