Professional Documents
Culture Documents
Write A Kotlin Prog To Create Excel File in Android
Write A Kotlin Prog To Create Excel File in Android
To create an Excel file in Android using Kotlin, you can use the Apache POI library.
Here is an example code that demonstrates how to create an Excel file with one sheet, add some
data to it, and save it to the device's storage:
implementation 'org.apache.poi:poi:5.2.0'
import android.os.Environment
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import java.io.FileOutputStream
fun createExcelFile() {
// create a new Excel workbook
for (i in rowData.indices) {
row.createCell(i).setCellValue(rowData[i])
for (i in personData.indices) {
for (j in personData[i].indices) {
row.createCell(j).setCellValue(personData[i][j])
}
workbook.write(fileOut)
fileOut.close()