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
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.