Easiest way to read Excel files in groovy?

前端 未结 3 910
挽巷
挽巷 2021-02-14 13:42

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

3条回答
  •  生来不讨喜
    2021-02-14 14:25

    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!

提交回复
热议问题