A Kotlin DSL to read/write XLSX files via Apache POI.
Really almost nothing here, the DSL is a facade for Apache POI, providing for somewhat simpler use.
workbook {
// Create a named cell style
val headerStyle = cellStyle("Header") {
fillForegroundColor = IndexedColors.GREY_25_PERCENT.index
fillPattern = FillPatternType.SOLID_FOREGROUND
}
sheet("One") {
// Add a row with a style
row(listOf("a", "b", "c"), headerStyle)
// Add a row without style
row(listOf(1, 2.0, 3L))
}
sheet {
row(listOf("A very wide cell"))
row(listOf("An even wider column"))
// Auto size the width of a column
autoSizeColumn(0)
}
}.write("test.xlsx")
workbook("test.xlsx") {
sheet("One") {
iterator().forEach { row ->
row.iterator().forEach { cell ->
println(cell.stringCellValue)
}
}
}
}