I have successfully created a button to execute a function that will actually grab the file off on my computer. But will not to completely import the data of that file into a new sheet tab.
My current code is:
Code.gs
/** * Displays an HTML-service dialog in Google Sheets that contains client-side * JavaScript code for the Google Picker API. */function showPicker() { var html = HtmlService.createHtmlOutputFromFile('dialog2.html') .setWidth(600) .setHeight(425) .setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi().showModalDialog(html, 'Select a file');}/** * Gets the user's OAuth 2.0 access token so that it can be passed to Picker. * This technique keeps Picker from needing to show its own authorization * dialog, but is only possible if the OAuth scope that Picker needs is * available in Apps Script. In this case, the function includes an unused call * to a DriveApp method to ensure that Apps Script requests access to all files * in the user's Drive. * * @return {string} The user's OAuth 2.0 access token. */function getOAuthToken() { DriveApp.getRootFolder(); return ScriptApp.getOAuthToken();}function upload(obj) { var file = DriveApp.createFile(obj.upload); return { fileId: file.getId(), mimeType: file.getMimeType(), fileName: file.getName(), };}
dialog2.html
<!DOCTYPE html><html><head><base target="_top"><link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"></head><body><form> <!-- Modified --><div id="progress"></div><input type="file" name="upload" id="file"><input type="button" value="Submit" class="action" onclick="form_data(this.parentNode)"><input type="button" value="Close" onclick="google.script.host.close()" /></form><script> function form_data(obj){ // Modified google.script.run.withSuccessHandler(closeIt).upload(obj); }; function closeIt(e){ // Modified console.log(e); google.script.host.close(); };</script></body></html>