Groovy中是否有可用於讀取Excel文件的warappers/utils?我正在尋找類似於Groovy SQL的行函數,如下面的spock測試示例所示。我的目的是用這個data driven testing using excel in Spock test framework在groovy中讀取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")
}
}
爲了使事情的人更容易一些,我轉身戈蘭的代碼放到一個GitHub庫。我也修改它以使用Grab的依賴關係,使用xlsx文件,併爲每個單元格返回字符串。使用細胞類型給我帶來麻煩,因爲我需要做的事情。 https://github.com/dtanner/groovy-excel-reader – 2014-03-27 14:53:01