2016-10-14 2 views
0

Google 시트의 단일 열에 마지막 값을 가져 오는 함수를 작성했습니다.특정 열의 마지막 값을 얻는 효율적인 방법

// Returns the row number of the first empty cell 
// Offset should be equal to the first row that has data 
function getLastRowInColumn(sheet, column, rowOffset) { 
    var lastRow = sheet.getMaxRows(); 
    for (var row = rowOffset; row < lastRow; row++) { 
    var range = sheet.getRange(row, column); 
    if (range.isBlank()) { 
     return row; 
    }; 
    } 
} 

I 모든 값은 따라서 기능을 실제로 발견 된 첫 번째 빈 셀 복귀되어 작성되는 것을 가정 할 수있다 (이 경우, 즉, 제 빈 행에 해당).

~ 1000 행의 시트를 실행하는 데 시간이 오래 걸립니다. 어떻게하면 더 효율적으로 만들 수 있습니까?

미리 감사드립니다.

답변

0

단지 행 것이다 기억 로컬 배열로 모든 데이터를 읽고 그 읽어 제로 인덱스 대신 1에서 시작하는 열 번호보다 (0에서 시작)

// Returns the row number of the first empty cell 
// Offset should be equal to the first row that has data 
function getLastRowInColumn(sheet, column, rowOffset) { 
    var lastRow = sheet.getMaxRows(); 
    var data = sheet.getDataRange().getValues() 
    for (var row = rowOffset; row < lastRow; row++) { 
    if (data[row][0] === '') { 
     return row; 
    }; 
    } 
} 
관련 문제