Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an excel with an object in Android and send it via Email

On my app I have an object of records, let's say I have todo a quiz with more than 5 guys, so I can then get the results of all of them and I have an Object with all of that information, is it possible to convert this Object to an Excel file? For example :

|---------------------|------------------|
|        Quiz         |     Question 1   |...
|---------------------|------------------|
|      Quiz Name      |    What's 1+1    |...
|---------------------|------------------|

Something like this, to know each user what answered and its score, all of it I have it on my Object.

And then if I can send it via Mail the .xls or whatever format.

EDIT

For example I'll need Quiz name and if I can add more about this quiz is ok, but then I need to add all of users have asked this quiz (another object from api) so I could get the name and the score.

I'd like to have a .csv or an Excel whatever where it says explicit :

Let's say I have a list of :

  1. createdAt
  2. updatedAt
  3. user (just the user.email)
  4. quiz (just the quiz.name)
  5. totalPoints

So I want to populate it to the .csv or an Excel whatever

like image 630
StuartDTO Avatar asked Mar 29 '19 10:03

StuartDTO


2 Answers

A CSV file is a simple comma separated text file. In your case, the format will be:

Quiz,Question 1
Quiz Name,What's 1+1

As long as you are able to write records in above format to a file with extension "csv", you will be able to open it in excel and email it too.

Please refer to following stackoverflow post.

How to create a .csv on android

like image 64
farhanjk Avatar answered Sep 20 '22 17:09

farhanjk


You can use Open CSV also.

<dependency> 
    <groupId>com.opencsv</groupId> 
    <artifactId>opencsv</artifactId> 
    <version>4.1</version> 
</dependency> 

you can refer this.

Java Object to CSV file

like image 44
Dhrumil Patel Avatar answered Sep 19 '22 17:09

Dhrumil Patel