Ich bin neu in der Welt von Google Scripting, und habe einige gute Tutorials zu finden, wie entweder: ich eine Datei auf Google Drive mit HTML-Formular hochladen ii Hängen Sie neue Zeilen an ein Google-Blatt an.HTML-Formular-Datei Upload auf Google Drive und speichern URL zu Google-Blatt
Im Wesentlichen versuche ich ein einfaches HTML-Formular zu schreiben, das ein paar Textfelder und Dateianhang sammelt, wo der Dateianhang auf mein Google Drive hochgeladen wird und der URL zusammen mit den anderen Formularfeldern ein Google-Blatt angehängt wird . Hier
ist das HTML-Formular mit denen ich arbeite (basierend auf einem Tutorial fand ich):
<!-- Include the Google CSS package -->
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons.css">
<!-- You can also include your own CSS styles -->
<style>
form { margin: 40px auto; }
input { display:inline-block; margin: 20px; }
</style>
<script>
// The function will be called after the form is submitted
function uploadFile() {
document.getElementById('uploadFile').value = "Uploading File..";
google.script.run
.withSuccessHandler(fileUploaded)
.uploadFiles(document.getElementById("labnol"));
return false;
}
// This function will be called after the Google Script has executed
function fileUploaded(status) {
document.getElementById('labnol').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
</script>
<!-- This is the HTML form -->
<form id="labnol">
<!-- Text input fields -->
<input type="text" id="nameField" name="myName" placeholder="Your name..">
<input type="email" id="emailField" name="myEmail" placeholder="Your email..">
<!-- File input filed -->
<input type="file" name="myFile">
<!-- The submit button. It calls the server side function uploadfiles() on click -->
<input type="submit" id="uploadFile" value="Upload File"
onclick="this.value='Uploading..';uploadFile();">
</form>
<!-- Here the results of the form submission will be displayed -->
<div id="output"></div>
Und hier ist der Google-Skript (wieder, basierend auf einem nützliches Tutorial auf einem Blog)
/* The script is deployed as a web app and renders the form */
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('form.html')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
// This is important as file upload fail in IFRAME Sandbox mode.
}
/* This function will process the submitted form */
function uploadFiles(form) {
try {
/* Name of the Drive folder where the files should be saved */
var dropbox = "Test Form Submissions";
var folder, folders = DriveApp.getFoldersByName(dropbox);
/* Find the folder, create if the folder does not exist */
if (folders.hasNext()) {
folder = folders.next();
} else {
folder = DriveApp.createFolder(dropbox);
}
/* Get the file uploaded though the form as a blob */
var blob = form.myFile;
var file = folder.createFile(blob);
//Allocate variables for submissions in sheet
var namerecord = form.myName;
var emailrecord = form.myEmail;
/* Set the file description as the name of the uploader */
file.setDescription("Uploaded by " + form.myName);
/* Return the download URL of the file once its on Google Drive */
return "File uploaded successfully " + file.getUrl();
var uploadURL = file.getUrl();
//
} catch (error) {
/* If there's an error, show the error message */
return error.toString();
}
//Open spreadsheet based on URL
var googsheet = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/17fuu1vUuxgCgs1TpSGpWDNxMHX3AEFscmjX156HQ5_U/edit?usp=sharing');
Logger.log(googsheet.getName());
var sheet = googsheet.getSheets()[0];
sheet.appendRow(["James", "jim", "abc"]);
}
Meine Intuition war einfach ein paar Zeilen Code in rutschen die Formulardaten an die angegebene Blatt hinzuzufügen, aber es funktioniert nicht und ich muss etwas falsch tun: S
Jede Beratung wäre grea tly geschätzt eine unwissende Business Analyst neu in Web-Programmierung:/
Dank
Sie werden zur Fehlerbehebung müssen lernen Techniken. [Google Doc - Fehlerbehebung] (https://docs.google.com/document/d/14BjSnTnzj7w9LV5id4Hc2z3jOYkH2hZduwLDxcYssWo/edit) Im Moment bitten Sie im Grunde um Code-Überprüfung, nicht um Hilfe bei einem bestimmten Fehler oder Problem. –