GroovyCSV is a library to make csv processing just a little bit Groovier. The library uses opencsv behind the scenes and merely tries to add a thin layer of “Groovy-ness” to the mix.
1.3
findAll
, collect
and so on)@Grab('com.xlson.groovycsv:groovycsv:1.3')
import static com.xlson.groovycsv.CsvParser.parseCsv
def csv = '''ID,Product
3,Shoe
1,Table'''
def data = parseCsv(csv)
for(line in data) {
println "ID=$line.ID, Product=$line.Product"
}
Output:
ID=3, Product=Shoe
ID=1, Product=Table
@Grab('com.xlson.groovycsv:groovycsv:1.3')
import com.xlson.groovycsv.CsvParser
def csv = '''Name-Lastname
Mark-'Anderson-Nielsen'
Pete-Hansen'''
def data = new CsvParser().parse(csv, separator: '-', quoteChar: "'")
for(line in data) {
println "$line.Name $line.Lastname"
}
Output:
Mark Andersson-Nielsen
Pete Hansen
@Grab('com.xlson.groovycsv:groovycsv:1.3')
import com.xlson.groovycsv.CsvParser
def csv = '''Apple,2
Pear,5'''
def data = new CsvParser().parse(csv, readFirstLine:true,
columnNames:['fruit', 'qty'])
for(line in data) {
println "$line.fruit ${line[1]}"
}
Output:
Apple 2
Pear 5
The Apache License, Version 2.0
Leonard Gram (leo@xlson.com)
GroovyCSV 1.3
GroovyCSV 1.2
GroovyCSV 1.1
GroovyCSV 1.0
GroovyCSV 0.2
You can also clone the project with Git by running:
$ git clone git://github.com/xlson/groovycsv