Save data to local csv

Hi, I’ve done my best to search for an answer so apologies if this has been covered elsewhere.

The app has some text inputs, location data, and Bluetooth LE data.

When all fields are completed, i’d like the user to be able to generate a csv file that is saved on their phone that records the data that was entered. The data doesn’t need to persist between sessions in the app. Is this possible and if so what’s the best way to go about it?

So do you want to export the csv file or simply display a spreadsheet with the data?

You can use a web viewer displaying a Google Sheet with the Google Sheets API to update the data.

Or you can just display an Airtable spreadsheet with the web viewer and update the data with blocks.

Yes, I’d like to export the csv file

https://json-csv.com/api
Perhaps this API will help you out.

Thanks renren66 I’ll check it out.

So there’s no way to build and save a file (csv, txt, pdf etc) locally+offline at this stage in X?

I’m interested in the same thing. Has anyone used the above https://json-csv.com/api successfully? Or figured how to create a shareable CSV? Any chance you’d share your blocks?

1 Like

изображение

2 Likes

Thanks very much, I’ll try that.

Thanks, I got the connection to work, but I don;t see how I can get a CSV file back? Only the same text that I send?

I showed you an example of working with the API. I didn’t see an example of working with files there.

I looked through the info for that API and a few others like it and I didn’t find anything that will return a CSV file that looks useable with Thunkable. They are almost all online generators that don’t have APIs associated. And the ones with APIs don’t seem to return files. :frowning:

Thanks so much for checking! Too bad there is no good solution for this at this time.

Hello, just want to ask, did you found a solution to export data?

Im looking aswell for a way to export data from a local database, I would create a json but i just still don’t know how to send it out of the app. Paid APIs are not an option for me.

Anyone?

Did you ever figure out a solution to this. I am looking at this 8 months later and still see no viable solution. I have an app that the user stores load information and would like the ability for them to email the loads to their superiors. If not the only way i can see this working is to use firebase and then return some json and maybe with blocks code create some sort of email response.

I haven’t figured out a clever way of saving files to the phone’s file system using Thunkable but I did manage to configure it to send the comma separated values in the form of the body of an email.

At some point I want to try replicating this in Thunkable using the open-ended functions or by simply editing the exported APK in android studio and adding this:

AHEM, MAYBE THUNKABLE FOLK ADD A MODULE FOR US INSTEAD… HINT HINT.

  String baseDir = android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
  String fileName = "AnalysisData.csv";
  String filePath = baseDir + File.separator + fileName;
  File f = new File(filePath);
  CSVWriter writer;

  // File exist
  if(f.exists()&&!f.isDirectory())
    {
      mFileWriter = new FileWriter(filePath, true);
      writer = new CSVWriter(mFileWriter);
    }
  else
    {
      writer = new CSVWriter(new FileWriter(filePath));
    }

    String[] data = {"Ship Name", "Scientist Name", "...", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").formatter.format(date)});

  writer.writeNext(data);

  writer.close();

I tried the blocks above…works but, not so well with 7 or 8 columns. CSV is exported like the image but does not convert to excel very well. what we need is the ability to do this.
Capture . This is from https://onlinecsvtools.com/ they might have an api

1 Like

Use Google sheet as your database and create a macro in the sheet to export to CSV.

Initially, that is where I was headed. But, found out that any Google sheet has a 100 user limit. That doesn’t allow for scalability. The app will have users…more than 100 hopefully :slight_smile: the firebase route is the obvious route, but I am not to versed in converting Json to a readable format. The users record load info. At anytime they need the ability to send one or more of these records to someone higher up…preferably in a readable format.

1 Like