cancel
Showing results for 
Search instead for 
Did you mean: 

Appgyver - Save EXCEL data in internal table storage

1,198

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

Accepted Solutions (0)

Answers (3)

Answers (3)

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).

0 Kudos

Dear Daniel,

I'm not really familiar with Javascript, could you please give me some guidance.

The Js code i used is :

function csvJSON(input1) { const lines = input1.split("\n"); const result = []; const 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]; }; result.push(obj); }; return JSON.stringify(result);};This code seems to be OK but still i don't have a result.I want to mention that the input is an UTF8 file string and the output is a list of objects with 2 properties.Thank you so much for your help.Best regards,Marouane
Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

See this post: https://forums.appgyver.com/t/file-uploader-excel-sheet/2425

You could also:

  • Upload a CSV and parse that.
  • Use SAP Build Process Automation to work with Excel.
  • Use an online API to convert Excel to JSON or CSV