1

I have the following use case:

I created a spreadsheet, in which I am trying to create a menu item that lets the user upload a text file from which to process and create a new sheet.

The lines of this text file have the following format:

[complexity] [package] [funcName] [absolutePathname]

What do you mean "process"?

By "processing the file", I mean, getting its contents, preferably as a BLOB or something similar, without uploading to the Drive (this project is for my employer, whose given me other main tasks, and who also has a shared Team Drive), transforming each line of data into the following format:

[package]/[filename] [complexity]

The problem

I already have my own algorithm for transforming the string line to this format, but first, I need to know how to upload the file.

It seems like everything I can find on file uploading, is outdated. For example, this resource is using all kinds of Google API functions that are deprecated.

User story(ies)

As a spreadsheet user, when I click on custom menu item to upload file a file upload prompt should appear.

The closest thing that I know of is to act on

SpreadsheetApp.getUi()

which returns a Ui. However, there's nothing in here that will easily create a file upload prompt. None of the available buttons are for file upload.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Mike Warren
  • 3,796
  • 5
  • 47
  • 99
  • Am I going to have to [whip out some HTML](https://developers.google.com/apps-script/reference/base/ui#showmodaldialoguserinterface-title), and if so, how do I get the form output from it? – Mike Warren Sep 23 '18 at 16:25
  • 2
    A form submit triggers a `doPost()` function in server code. Alternatively, You can prevent forms from submitting and run your own server code with ``google.script.run``. This is a exact duplicate of [forms](https://developers.google.com/apps-script/guides/html/communication#forms), were the code in SO. – TheMaster Sep 23 '18 at 16:35

1 Answers1

1

You will need to present a UI of your making.

As I'-'I commented on your question, you can use a combination of conventional HTML Form with client-side and then server-side scripting.

Alternatively, you can leverage the Google Picker API. Once uploaded the file will be in Google Drive, and you can process and delete and/or store the source and results. This brings UI consistency with Google Sheets, and some degree of error handling / auditing.

Either UI can either be served as a modal from the menu command or you can trigger it from a sidebar.

JSDBroughton
  • 3,966
  • 4
  • 32
  • 52