Android - Generate CSV file from table values

后端 未结 5 864
半阙折子戏
半阙折子戏 2020-12-01 04:47

I have a database containing one table, i want to generate CSV file with values of this table.

Actually, I want to email this CSV file as an attachment. I know about

5条回答
  •  一生所求
    2020-12-01 05:19

    You can use opencsv for this

    Download the library from here:

    http://sourceforge.net/projects/opencsv/

    In this you can find jar file.

    Inside your activity use this:

    CSVWriter writer = null;
    try 
    {
        writer = new CSVWriter(new FileWriter("/sdcard/myfile.csv"), ',');
        String[] entries = "first#second#third".split("#"); // array of your values
        writer.writeNext(entries);  
        writer.close();
    } 
    catch (IOException e)
    {
        //error
    }
    

提交回复
热议问题