2017-01-14 3 views
0

나는 간단한 Google 스크립트를 사용하고 있지만 작동을 시도하고 있지만 내 오류를 이해하지 못하는 것 같습니다.동일한 스프레드 시트에서 다른 셀로 셀 값 이동

이 함수는 빈 셀을 찾은 후 스프레드 시트의 한 섹션에서 다른 시트로 굵게 표시되지 않는 텍스트를 이동하려고합니다.

나는 값이 굵게 또는 굵게하고 빈 셀의 위치를 ​​가중하는 경우 나, 값을 얻을 수 있습니다 확인하지만, 한 나는이 오류 메시지가 얻을 텍스트 이동하려고하면

TypeError: Cannot find function copyTo in object AS.

내 오류가이 라인에서 알고 :

matchedCell.getValue().copyTo((emptyCellLocation,1,1,1),{contentsOnly:true}); 

제안? 숫자, 문자열, 또는 일 :

function moveLowerValues() { 

    var s = SpreadsheetApp.getActiveSheet(); 

    // Set values for position of cells to examine 

    var upperRowStart = 1; 
    var columnStart = 1; 

    var upperRange = s.getRange(upperRowStart, columnStart, 10); 

    var upperValues = upperRange.getValues(); // Get all data in one call 
    var emptyCellLocation = 1; 

    while (upperValues[emptyCellLocation][0] != "") { 
    emptyCellLocation++; 
    } 

    var lowerRowStart = 11; 
    var lowerRange = s.getRange(lowerRowStart, columnStart, 10); 

    var lowerValues = lowerRange.getValues(); 

    var lowerWeight = lowerRange.getFontWeights(); 

    // Move and clear cells which are not bold 

    for (var rowStartOffset=0; rowStartOffset < lowerValues.length; rowStartOffset++) { 

    // If the value of the cell does not equal bold, move and then delete it 

    if (lowerWeight[rowStartOffset].toString() != "bold") { 

     var matchedRow = lowerRowStart + rowStartOffset; 
     var matchedCell = s.getRange(matchedRow, columnStart, 1, 1); 
     matchedCell.getValue().copyTo((emptyCellLocation,1,1,1),{contentsOnly:true}); 
     // emptyCellLocation++ 
     // matchedCell.clear(); 

    } 
    } 

    // lowerRange.sort(1); 

} 

답변

1

matchedCell.getValue()는 셀의 값을 반환합니다. 이 값에는 copyTo 메쏘드가 없습니다. 이 메서드는 Range 개체에있는 메서드입니다. 대신 matchedCell.copyTo을 사용하십시오.

또한 copyTo의 첫 번째 인수는 Range 클래스의 객체 여야합니다. (emptyCellLocation,1,1,1)을 쓰는 것은 그러한 객체를 생성하지 않습니다. getRange 방법을 사용하십시오.

+0

이것은 내 실수였습니다. 감사! – Chef1075