2013-10-21 3 views
1

정보를 업데이트하려면 Google 스프레드 시트의 정보를 Google 양식으로 다시 가져올 수 있습니까?Google 스프레드 시트 정보를 Google 양식

이미 Google 양식을 통해 제출 한 정보를 정보를 업데이트하기위한 양식으로 다시 가져올 수 있기를 바랍니다. 나는 스프레드 쉬트를 편집 할 수 있다는 것을 알고 있지만, 제 목적을 위해 스프레드 쉬트를 통해 그것을하는 것이 더 쉬울 것입니다. 나는 이것을 할 수있는 스크립트를 찾을 수 없었다. 누구든지 어떤 제안이 있습니까?

답변

3

Apps Script에서 FormApp를 사용하여 업데이트 할 양식 객체에 액세스 할 수 있습니다.

다음은 "목록에서 선택"개체를 업데이트하는 예입니다. 각 제출 후에 양식을 갱신하려는 경우 컨테이너 기반 트리거 "양식 제출시"를 사용하여 updateList 함수를 호출 할 수 있습니다.

function updateList(){ 
    var form = FormApp.openById(formId); 
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName); 
    // get the range of values to update in the form 
    var data = sheet.getRange(2,1,sheet.getLastRow(),sheet.getLastColumn()).getValues(); 

    var listItemsToAdd = []; 
    for(s in data){ 
    if(logic to define if to add to the form){ 
     listItemsToAdd.push(data[s][0]); 
    } 
    } 

    // get all the list items in the form 
    var list = form.getItems(FormApp.ItemType.LIST); 
    // grab the first list item in the array of the form's list items 
    var item = list[0].asListItem(); 
    // set the options to the array just created 
    item.setChoiceValues(listItemsToAdd); 
} 
+1

그러나 'for (s in data)'는 배열을 순환하지 마십시오. –

+1

@Cyrus Loree : Ok,하지만 이것에 대한 질문을하고 싶습니다. 탐색 유형으로 for 루프 내의 값을 어떻게 설정합니까? ([이 예제와 같이] (https://developers.google.com/apps-script/reference/forms/choice) –

+0

다른 대화라고 생각합니다. 새로운 질문을 게시하면 기꺼이 자세히 설명하겠습니다. 짧은 대답은 PageNavigationType 열거 대신 페이지 나누기 항목을 전달한다는 것입니다. E.G. var anotherPage = form.addPageBreakItem(). setTitle ('이동할 다른 페이지'); ... item.createChoice ('내 새 페이지', 다른 페이지), item.createChoice ('Dogs', FormApp.PageNavigationType.RESTART) ]); –