DEV Community

loizenai
loizenai

Posted on

Kotlin – How to read/write Excel file with Apache POI

https://grokonez.com/kotlin/kotlin-read-write-excel-file-apache-poi-example

Kotlin – How to read/write Excel file with Apache POI

In this tutorial, we're gonna look at Kotlin examples that read and write Excel file using Apache POI.

I. Dependency

<dependency>
    <groupId>org.jetbrains.kotlin</groupId>
    <artifactId>kotlin-stdlib</artifactId>
    <version>1.2.21</version>
</dependency>

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.17</version>
</dependency>

II. Write Data to Excel File

  • Simple POJO Customer (id, name, address, age):
    
    package com.javasampleapproach.kotlin.apachecsv

class Customer {
var id: String? = null
var name: String? = null
var address: String? = null
var age: Int = 0

constructor() {}
constructor(id: String?, name: String?, address: String?, age: Int) {
    this.id = id
    this.name = name
    this.address = address
    this.age = age
}

override fun toString(): String {
    return "Customer [id=" + id + ", name=" + name + ", address=" + address + ", age=" + age + "]"
}
Enter fullscreen mode Exit fullscreen mode

}

  • Write to Excel file:

More at:
https://grokonez.com/kotlin/kotlin-read-write-excel-file-apache-poi-example

Kotlin – How to read/write Excel file with Apache POI

Top comments (0)