I would like to save the data extracted from the content provider into the sdcard in excel format. How do i go about it? I have retrieve the data using the cursor.
2 Answers
Simplest thing is to save using CSV to a text file. Excel will allow an easy import of CSV files.
EDIT:
A CSV file is just a text file which has the following format...
value1,value2,value3
In other words each value (or record) is separated by a comma. CSV files aren't the best way to pass certain types of data but as long as none of the values/records have a comma within them they are very simple.
You can create a CSV file which has the first line which designates the column names for Excel such as...
FirstName,LastName,PayrollNumber
John,Smith,1234
Bill,Jones,5678
When you import into Excel it should give the option to use the first line of the file as the column names and the other lines as the data (values / records). You can also easily write VBA macros for Excel to do this automatically.

- 48,735
- 19
- 103
- 135
-
what do you mean by using CSV to text file?? – user669046 Apr 25 '11 at 01:01
-
@user669046: See the EDIT to my answer. – Squonk Apr 25 '11 at 02:56
You can either save a csv file (just a plain text file with comma separated values) or try the library linked in this answer: Working with Excel files on Android
This is a very simplified example that does not even consider if your values have commas in it, but it should give you an idea:
public void write() {
BufferedWriter out;
try {
out = new BufferedWriter(new FileWriter("outfilename"));
Cursor cursor = getYourData();
while (cursor.moveToNext()) {
out.write(cursor.getString(YOURFIRSTCOLUMN) + "," + cursor.getString(YOURSECONDCOLUMN) + "," + cursor.getString(YOURTHIRDCOLUMN));
out.newLine();
}
} catch (IOException e) {
// handle any error here
} finally {
out.close();
}
}
-
-
It's very simple. Just add a comma after each value (except the last one in the row) – Aleadam Apr 25 '11 at 01:25