I would like to use Apache POI to read/create Excel files in an Scala app. Sure, I can use the POI library directly, it's Java after all, but I would like to have the Scala feel. So is there a Scala wrapper bringing the Scala feel (using implicit conversions), i.e. some kind of "Scala-POI-DSL" freely available?
Apache POI provides Java API for manipulating various file formats based on the Office Open XML (OOXML) standard and OLE2 standard from Microsoft. Apache POI releases are available under the Apache License (V2. 0).
ExcelAnt is a set of Ant tasks that make it possible to verify or test a workbook without having to write Java code.
Thanks to Dave Griffith's answer, I've hacked something similar to his DSL.
Workbook {
Sheet("name") {
Row(1) {
Cell(1, "data") :: Cell(2, "data2") :: Nil
} ::
Row(2) {
Cell(1, "data") :: Cell(2, "data2") :: Nil
} :: Nil
} ::
Sheet("name2") {
Row(2) {
Cell(1, "data") :: Cell(2, "data2") :: Nil
} :: Nil
} :: Nil
}.save("/home/path/ok.xls")
Code can be found here.
Given the lack of advanced, open source spreadsheet wrappers for Scala, I've started the development of Spoiwo: https://github.com/norbert-radyk/spoiwo. It allows the generation of the XSSFWorkbook and supports a significant subset of POI's functionality.
It still requires a bit of documentation, but the below should give a rough idea about its capabilities:
The example of simple spreadsheet using Spoiwo:
object GettingStartedExample {
val headerStyle =
CellStyle(fillPattern = CellFill.Solid, fillForegroundColor = Color.AquaMarine, fillBackgroundColor = Color.AquaMarine, font = Font(bold = true))
val gettingStartedSheet = Sheet(name = "Some serious stuff")
.withRows(
Row(style = headerStyle).withCellValues("NAME", "BIRTH DATE", "DIED AGED", "FEMALE"),
Row().withCellValues("Marie Curie", new LocalDate(1867, 11, 7), 66, true),
Row().withCellValues("Albert Einstein", new LocalDate(1879, 3, 14), 76, false),
Row().withCellValues("Erwin Shrodinger", new LocalDate(1887, 8, 12), 73, false)
)
.withColumns(
Column(index = 0, style = CellStyle(font = Font(bold = true)), autoSized = true)
)
def main(args: Array[String]) {
gettingStartedSheet.saveAsXlsx("C:\\Reports\\getting_started.xlsx")
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With