开发者

Android SMS - in excel format

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 retrie开发者_JS百科ve the data using the cursor.


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.


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();
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜