cancel
Showing results for 
Search instead for 
Did you mean: 

Appgyver - Save EXCEL data in internal table storage

1,200

Dear Community,

I just started working with appgyver and i faced an issue while trying to convert Excel file data to data that can be stored on internal device storage.

I used the Pick files flow function to choose the Excel file from my internal storage and read file to get the file string.

How can i use this string file and transform it to data i can store in my device's internal storage ?

Thank you for your help.

Best regards,

Marouane

View Entire Topic
Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

Can you show a screenshot of your JS and show the result you get and the result you want? I am assuming the file being uploaded is a CSV, not a native Excel, which wasn't clear.

I am able to do this. I create a flow function to select a file, then read it, the parse it with JS:

Then the JS I set the input to the output of my read file flow function, and I also add a second output for errors. The code is this:

try {
  data = [];
  a = inputs.input1;
  lines = inputs.input1.split("\n");

  headers = lines[0].split(",");
  for (let i = 1; i < lines.length; i++) {
      if (!lines[i])
        continue 
      const obj = {};
      const currentline = lines[i].split(",");
      for (let j = 0; j < headers.length; j++) {
        obj[headers[j]] = currentline[j];
      };
      data.push(obj);

  };
  return { result: data };
}
catch (err) {
    const error = {
      code: 'unknownError',
      message: 'Something went wrong.',
      rawError: err,
    }
  
    return [1, { error }]

}

DISCLAIMER: I never guarantee the syntax of my code, and there may be differences between running on mobile device and laptop (the read file did not work on web).