1
votes

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.

1
Am I going to have to whip out some HTML, and if so, how do I get the form output from it? - Mike Warren
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, were the code in SO. - TheMaster

1 Answers

1
votes

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.