Excel Parsing with Function(TypeScript)

Is it possible to parse an Excel file using a function? I want to upload an Excel file as an attachment using Workshop(using Action button),and trigger action to parse the attachment(excel file)'s contents, and then store the data as objects. Is this possible?

You can take an Attachment as an input to a Function and then read the binary data as a Blob using the provided APIs.

You’d need to find a library to parse the Excel file into readable contents. Note some caveats on reading file data when libraries assume the existence of the fs library in this section of the documentation. The xlsx library is fairly widely used and should work in the environment Functions are executed in.

Your code will probably want to look something like this (depending on which library you opt for):

@OntologyEditFunction()
@Edtis(...)
public async myFunction(attachment: Attachment): Promise<void> {
   const blob = await attachment.readAsync();
   const buffer = await blob.arrayBuffer();
   const workbook = XLSX.read(buffer, ...);

   // use the data from workbook to edit Ontology objects
}
2 Likes

Amazing. Thank you so much!