GroovyCSV

Library for parsing csv in Groovy

License

License

Categories

Categories

Groovy Languages CSV Data Data Formats
GroupId

GroupId

com.xlson.groovycsv
ArtifactId

ArtifactId

groovycsv
Last Version

Last Version

1.3
Release Date

Release Date

Type

Type

jar
Description

Description

GroovyCSV
Library for parsing csv in Groovy
Project URL

Project URL

http://github.com/xlson/groovycsv
Source Code Management

Source Code Management

http://github.com/xlson/groovycsv

Download groovycsv

How to add to project

<!-- https://jarcasting.com/artifacts/com.xlson.groovycsv/groovycsv/ -->
<dependency>
    <groupId>com.xlson.groovycsv</groupId>
    <artifactId>groovycsv</artifactId>
    <version>1.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.xlson.groovycsv/groovycsv/
implementation 'com.xlson.groovycsv:groovycsv:1.3'
// https://jarcasting.com/artifacts/com.xlson.groovycsv/groovycsv/
implementation ("com.xlson.groovycsv:groovycsv:1.3")
'com.xlson.groovycsv:groovycsv:jar:1.3'
<dependency org="com.xlson.groovycsv" name="groovycsv" rev="1.3">
  <artifact name="groovycsv" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.xlson.groovycsv', module='groovycsv', version='1.3')
)
libraryDependencies += "com.xlson.groovycsv" % "groovycsv" % "1.3"
[com.xlson.groovycsv/groovycsv "1.3"]

Dependencies

compile (1)

Group / Artifact Type Version
com.opencsv : opencsv jar 4.0

test (3)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.1-groovy-2.4-rc-2
cglib : cglib-nodep jar 2.2
org.objenesis : objenesis jar 1.2

Project Modules

There are no modules declared in this project.

GroovyCSV

GroovyCSV is a library for Groovy which aims to make csv data easier (and more idiomatically Groovy) to work with. The library was inspired by @goeh's ExcelBuilder that lets you iterate over rows in the excel file using eachLine and access values using the column names.

Features

  • Value-access by header name or position
  • Iteration using the ordinary collection methods (findAll, collect and so on)
  • Support for guessing separator and/or quote character
  • Support for reading csv without headers
  • Support for skipping initial lines of the csv

Example

The parse method returns an iterator over the rows in the csv. This means we can use any of the default groovy ways to iterate, in this example we see the for each loop in use.

@Grab('com.xlson.groovycsv:groovycsv:1.3')
import static com.xlson.groovycsv.CsvParser.parseCsv

def csv = '''Name,Lastname
Mark,Andersson
Pete,Hansen'''

def data = parseCsv(csv)
for(line in data) {
    println "$line.Name $line.Lastname"
}

The parse method takes a String or a Reader as argument.

Output:

Mark Andersson
Pete Hansen

Getting GroovyCSV

GroovyCSV is available through Maven Central.

Maven & Ivy configuration

Latest stable

  • GroupId: com.xlson.groovycsv
  • ArtifactId: groovycsv
  • Version: 1.3

Latest snapshot

Downloads

GroovyCSV 1.3

Dependencies

Many thanks to everyone who's contributed to the project and everyone in the OpenCSV team for doing all the heavy lifting.

Building

GroovyCSV uses Gradle for building as is packaged with the gradle wrapper which will download and install gradle for you behind the scenes the first time you run it.

Build instruction

  1. Fetch the latest code: git clone git://github.com/xlson/groovycsv.git
  2. (Optional) Run the tests using the gradle wrapper ./gradlew test
  3. Go to the project directory and run: ./gradlew jar

You will find the built jar in ./build/libs. If you need any dependencies you can download them using ./gradlew downloadDeps, they end up in the lib folder.

Versions

Version
1.3
1.2
1.1
1.0
0.2