Android - Generate CSV file from table values

后端 未结 5 867
半阙折子戏
半阙折子戏 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:29

    In case of using Kotlin, I recommend kotlin-csv library.

    Just get the list of DB table objects, go through all of them and add the column values to CSV rows, one by one, like this:

    csvWriter().open(csvFile) {
        // Header
        writeRow(listOf("[id]", "[name]", "[age]"))
    
        peopleList.forEachIndexed { index, person ->
            writeRow(listOf(index, person.fullName, person.age))
        }
    }
    

    I explain the whole process of creating csv file here.

提交回复
热议问题