在groovy中读取Excel文件的最简单方法?

是否有任何warappers / utils可用于读取Groovy中的Excel文件。 我正在寻找类似于Groovy SQL的函数的东西,如下面的spock测试示例所示。 我的目的是在Spock测试框架中使用excel进行数据驱动测试

import groovy.sql.Sql import spock.lang.* class DatabaseDriven extends Specification { @Shared sql = Sql.newInstance("jdbc:h2:mem:", "org.h2.Driver") // normally an external database would be used, // and the test data wouldn't have to be inserted here def setupSpec() { sql.execute("create table maxdata (id int primary key, a int, b int, c int)") sql.execute("insert into maxdata values (1, 3, 7, 7), (2, 5, 4, 5), (3, 9, 9, 9)") } def "maximum of two numbers"() { expect: Math.max(a, b) == c where: [a, b, c] << sql.rows("select a, b, c from maxdata") } } 

我的一位GUG成员创建了一个使用Apache POI处理Excel的工具,其方式与您描述的方式非常相似。 它尚未正式化为图书馆(AFAIK),但可以在他的博客上找到。

它允许您编写如下代码:

 new ExcelBuilder("customers.xls").eachLine([labels:true]) { new Person(name:"$firstname $lastname", address:address, telephone:phone).save() } 

请在此处查看: http : //www.technipelago.se/content/technipelago/blog/44

POI是您在http://poi.apache.org/之后的Java Lib,因此您可以在Groovy中使用它。 不知道在任何地方是否有Groovy包装器