2017-07-12 4 views
2

Ich möchte ein Skript erstellen, das eine Menge (ca. 1500) CV und Kandidateninformationen als Antwort auf ein Formular hinzufügen wird. Ich habe die Informationen als Google-Tabelle. Ich verknüpfte es mit Formular, aber ich kann nur Antworten verwalten. Selbst wenn ich die Tabelle ändere (oder hinzufüge), wird keine Aktualisierung im Formular stattfinden. Ich füge Zeilen hinzu, aber keine Antworten hinzugefügt. Ist das möglich? Ich habe 2-3 Fragen dazu gelesen, aber sie waren alt und ich versuche immer noch Antworten zu bekommen. Dies ist mein Praktikumsprojekt und ich habe nicht mehr viel Zeit. Danke im Voraus.Viele Antworten mit Google Apps Skript hinzufügen

+0

Sie sind also besorgt über die Statistiken der Antworten, die im Formular sichtbar sind? – Jonathon

+0

Nein. Ich möchte eine Antwort über die Formular- und Blatt-API hinzufügen. Ich habe 1500 Zeilen Info, jede Zeile muss eine Antwort sein. Ich muss sie als Antwort hinzufügen, aber anstatt es mit meinen Händen zu machen, schrieb ich ein Programm. Ich habe das Blatt zu Formular verknüpft. Aber ich konnte die Zeilen nicht als Antworten hinzufügen. – Kistarianth

+2

Wenn Sie Ihren Code posten, können Leute helfen, die beiden zu verknüpfen oder herauszufinden, warum das, was Sie haben, nicht funktioniert. – Jonathon

Antwort

1

Zum Beispiel können Sie Ihre Antworten in eine Tabelle hochladen, sie in Array und senden Sie über FormResponce Objekt (für das müssen Sie Form#createResponse verwenden).

Ich habe diesen Code nicht getestet, aber soweit ich weiß, sollte so etwas für Sie funktionieren.

var ANSWER_SHEET_ID = "xxx"; 
var FORM_ID = "yyy"; 

function myFunction() { 
    const answers = SpreadsheetApp.openById(ANSWERS_SHEET_ID) 
         .getSheetByName('answers') //Let's say that sheet is named 
         .getRange(answerSheet.getLastRow(), answerSheet.getLastColumn()) 
         .getValues() //get it as the Array 
         .slice(1); //slice the header row if it exists in your answer_sheet 

    const form = FormApp.openById(FORM_ID); 

    const formResponse = form.createResponse(); 
    const items = form.getItems(); 

    for(var i=0, len=answers.length; i<len; ++i){ 
    //you have to define types of your Items like this 
    formResponse.withItemResponse(items[0].asTextItem().createResponse(answers[i][0])) //for Text Item 
       .withItemResponse(items[1].asMultipleChoiceItem().createResponse(answers[i][1])) //Multiple Choice Item 
       .withItemResponse(items[2].asScaleItem().createResponse(parseInt(answers[i][2]))) //for Scale Item !! requires integer as a response 
       .submit(); 
    } 
} 

vorsichtig sein, einfach, einige Elemente erfordern Integer als eine Antwort, während andere String usw.

+0

Es hat funktioniert? Ich habe fast 60 Artikel in meinem Blatt, ich habe für jeden von ihnen versucht. Antworten werden hinzugefügt, aber die Felder sind leer. Aber du hast das wahre Problem gelöst! Ich danke dir sehr. – Kistarianth

+0

@Kristianth, teile dein Skript mit uns =) wir werden sehen, was los ist) –

1

Dank euch erwarten, könnte ich ein Element als Reaktion hinzuzufügen. Es ist der große Start für mich! Hier ist der Code, den ich geschrieben habe:

const answers = sheet.getSheetValues(2, 2, sheet.getLastRow()-2, sheet.getLastColumn()-2); 


var formResponse = new Array(answers.length); 
for(var i =0; i < answers.length; ++i) 
formResponse[i] = form.createResponse(); 

const items = form.getItems(); 

for(var i=0, len=answers.length; i<len; ++i){ 

    formResponse[i] 
    .withItemResponse(items[1].asDateItem().createResponse(answers[i][0])) 
    .withItemResponse(items[2].asTextItem().createResponse(answers[i][1])) 
    .withItemResponse(items[3].asTextItem().createResponse(answers[i][2])) 
    .withItemResponse(items[4].asTextItem().createResponse(answers[i][3])) 
    .withItemResponse(items[5].asTextItem().createResponse(answers[i][4])) 
    .withItemResponse(items[6].asDateItem().createResponse(answers[i][5])) 
    .withItemResponse(items[7].asParagraphTextItem().createResponse(answers[i][6])) 
    .withItemResponse(items[8].asTextItem().createResponse(answers[i][7])) 
    .withItemResponse(items[9].asTextItem().createResponse(answers[i][8])) 
    .withItemResponse(items[10].asListItem().createResponse(answers[i][9])) 
    .withItemResponse(items[11].asListItem().createResponse(answers[i][10])) 

    .withItemResponse(items[12].asParagraphTextItem().createResponse(answers[i][11])) 
    .withItemResponse(items[13].asParagraphTextItem().createResponse(answers[i][12])) 
    .withItemResponse(items[14].asParagraphTextItem().createResponse(answers[i][13])) 
    .withItemResponse(items[15].asParagraphTextItem().createResponse(answers[i][14])) 
    .withItemResponse(items[16].asParagraphTextItem().createResponse(answers[i][15])) 

    .withItemResponse(items[18].asTextItem().createResponse(answers[i][16])) 

    //.withItemResponse(items[19].asCheckboxItem().createResponse(answers[i][17])) 

    .withItemResponse(items[21].asTextItem().createResponse(answers[i][18])) 
    .withItemResponse(items[22].asListItem().createResponse(answers[i][19])) 
    .withItemResponse(items[23].asTextItem().createResponse(answers[i][20])) 
    .withItemResponse(items[24].asListItem().createResponse(answers[i][21])) 
    .withItemResponse(items[25].asTextItem().createResponse(answers[i][22])) 
    .withItemResponse(items[26].asListItem().createResponse(answers[i][23])) 

    .withItemResponse(items[28].asTextItem().createResponse(answers[i][24])) 
    .withItemResponse(items[29].asTextItem().createResponse(answers[i][25])) 
    .withItemResponse(items[30].asTextItem().createResponse(answers[i][26])) 
    .withItemResponse(items[31].asTextItem().createResponse(answers[i][27])) 
    .withItemResponse(items[32].asTextItem().createResponse(answers[i][28])) 
    .withItemResponse(items[33].asTextItem().createResponse(answers[i][29])) 

    .withItemResponse(items[35].asTextItem().createResponse(answers[i][30])) 
    .withItemResponse(items[36].asParagraphTextItem().createResponse(answers[i][31]))  
    .withItemResponse(items[37].asParagraphTextItem().createResponse(answers[i][32])) 
    .withItemResponse(items[38].asParagraphTextItem().createResponse(answers[i][33])) 



    .withItemResponse(items[40].asTextItem().createResponse(answers[i][34])) 
    .withItemResponse(items[41].asListItem().createResponse(answers[i][35])) 
    .withItemResponse(items[42].asParagraphTextItem().createResponse(answers[i][36])) 

    .withItemResponse(items[44].asDateItem().createResponse(answers[i][37])) 
    .withItemResponse(items[45].asTextItem().createResponse(answers[i][38])) 
    .withItemResponse(items[46].asParagraphTextItem().createResponse(answers[i][39])) 

    .withItemResponse(items[48].asDateItem().createResponse(answers[i][40])) 
    .withItemResponse(items[49].asTextItem().createResponse(answers[i][41])) 
    .withItemResponse(items[50].asParagraphTextItem().createResponse(answers[i][42])) 

    .withItemResponse(items[52].asDateItem().createResponse(answers[i][43])) 
    .withItemResponse(items[53].asTextItem().createResponse(answers[i][44])) 
    .withItemResponse(items[54].asParagraphTextItem().createResponse(answers[i][45])) 

    .withItemResponse(items[55].asTextItem().createResponse(answers[i][47])) 
    .withItemResponse(items[56].asParagraphTextItem().createResponse(answers[i][48])) 
    .withItemResponse(items[57].asParagraphTextItem().createResponse(answers[i][49])) 
    .withItemResponse(items[58].asTextItem().createResponse(answers[i][50])) 
    .withItemResponse(items[59].asTextItem().createResponse(answers[i][51])) 
    .withItemResponse(items[60].asTextItem().createResponse(answers[i][52])) 
    .submit(); 

} 

Ich tat, wie Rudolf sagt. Danke für die Hilfe. Wenn jemand mehr über diese eine Antwort weiß, wäre ich sehr dankbar dafür.

Verwandte Themen