on 2022 Dec 02 11:46 PM
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
Request clarification before answering.
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).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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,MarouaneYou must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See this post: https://forums.appgyver.com/t/file-uploader-excel-sheet/2425
You could also:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
46 | |
9 | |
8 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.