Export class to Excel/CSV?

309 views
Skip to first unread message

Ruben

unread,
May 19, 2016, 10:52:40 AM5/19/16
to back{4}app
Hi!

How is the best way to export a class with the data containing to a Excel format or CSV?
That would be a very crucial feature for us.


Thanks!
Ruben

Davi Macêdo

unread,
May 22, 2016, 12:29:25 AM5/22/16
to back{4}app
Hi Ruben. This feature is not yet available. The best way to do it is to write a script to reach the api and write the file. Another option is export directly from mongodb database. Best!

price...@gmail.com

unread,
May 22, 2016, 10:09:44 AM5/22/16
to back{4}app
Hi Davi! Can you make example or quide about export directly from mongodb database?

Davi Macêdo

unread,
May 22, 2016, 9:23:10 PM5/22/16
to back{4}app
Hi. To export directly from mongodb you can use mongodump command as specified in the link below:

rmkons...@gmail.com

unread,
May 23, 2016, 10:15:24 AM5/23/16
to back{4}app
Ok! Thank you!=)

in...@rubentavares.de

unread,
May 24, 2016, 2:21:41 PM5/24/16
to back{4}app
Hi Davi, do you have an example for the script API method? Would this work over the cloud code import file way? Thanks!

Davi Macêdo

unread,
May 26, 2016, 8:24:11 PM5/26/16
to back{4}app
Hi.

I built a public API to exemplify.

This is the public API:

And here is the example:

Basically you have to upload a cloud code file like this one here:

And run a curl command like this one here:

It is limited to 100 rows. You can increase this limit to 1000 rows using limit() function. If you need more than it you have to change the code little bit to retrieve 1000 then 1000...

Best.

Ruben

unread,
Jun 2, 2016, 1:48:07 AM6/2/16
to back{4}app
Hi Davi,

thanks!
Could you exemplify the code to be used for >1000 rows?
I am a newbie in curl. And I need this function urgently today.

But your code for 100 rows works for me :)

Thanks!
Ruben Tavares

in...@rubentavares.de

unread,
Jun 2, 2016, 2:12:28 AM6/2/16
to back{4}app
Hi Davi,

I would maybe also want this to be executed via a button on a webpage.
I want it to be saved on the server as results.json. How do I accomplish that?

But it's not saving out.json anywhere. Would I need to specify the path?


Thanks!
Ruben Tavares

Davi Macêdo

unread,
Jun 6, 2016, 9:34:36 PM6/6/16
to back{4}app
Hi, Ruben.

Sorry about the delay.

You can try something like it to export all data:
Parse.Cloud.define("export", function (request, response) {
  var consolidatedResults = [];
  export1000();
  function export1000 (partialResults) {
    if (partialResults) {
      consolidatedResults = consolidatedResults.concat(partialResults);
      if (partialResults.length < 1000) {
        response.success(consolidatedResults);
        return;
      }
    }
    var ExportObject = Parse.Object.extend(request.params.exportClass);
    var query = new Parse.Query(ExportObject);
    query.limit(1000);
    query.skip(consolidatedResults.length);
    query.find({ success: export1000, error: response.error });
  }
});

I have not tested ok? :)

Please, let me know.

Davi Macêdo

unread,
Jun 6, 2016, 9:50:07 PM6/6/16
to back{4}app
Hi, Ruben.

About exporting button, the stackoverflow response seems to work fine. But you have to make sure that you have php installed.

It will probably create the file in the same folder the application is running.

Best!
Reply all
Reply to author
Forward
0 new messages