Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Scala wrapper for Apache POI?

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?

like image 368
Peter Kofler Avatar asked Feb 17 '11 17:02

Peter Kofler


People also ask

What is the use of poi ooxml?

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

What is Poi ExcelAnt?

ExcelAnt is a set of Ant tasks that make it possible to verify or test a workbook without having to write Java code.


2 Answers

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.

like image 60
George Avatar answered Nov 16 '22 00:11

George


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 Quick Start Guide
  • The rewritten version of POI Busy Developers' Guide

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")
  }
} 
like image 31
Norbert Radyk Avatar answered Nov 15 '22 22:11

Norbert Radyk