Are there any warappers/utils available to read Excel files in Groovy. I am looking for something similar to Groovy SQL\'s rows function as shown in below spock test ex
I could also recommend use Groovy Spreadsheet Builder. It available in maven repository (contrary to ExcelBuilder
) and also have expressive Groovy-syntax:
SpreadsheetQuery query = PoiSpreadsheetCriteria.FACTORY.forFile(file) // <1>
Collection cells = query.query {
sheet {
row {
cell {
value 'B'
}
}
}
}
assert cells.size() == 1
assert cells.first().value == 'B'
Or:
Collection rows = query.query {
sheet(name({ name.startsWith('Con') })) {
row(1)
}
}.rows
Documentation contains many examples. It even may write Excel files in same way!
POI is what your after http://poi.apache.org/ its a Java Lib so you can use it from Groovy. Not sure if there are Groovy wrappers for it anywhere
One of my fellow GUG members has created a tool for working with Excel using Apache POI in very much the same way you describe. It's not formalized into a library yet (AFAIK) but is available on his blog.
It allows you to write code like this:
new ExcelBuilder("customers.xls").eachLine([labels:true]) {
new Person(name:"$firstname $lastname",
address:address, telephone:phone).save()
}
Check it out here: http://www.technipelago.se/content/technipelago/blog/44