Coder Social home page Coder Social logo

groovycsv's Introduction

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.

Important

Package structure was changed from com.xlson.csvparser to com.xlson.groovycsv between release 0.1 and 0.2.

Features

  • Value-access by header name or position
  • Iteration using the ordinary collection methods (findAll, collect and so on)
  • Full support for OpenCSV's configurability
  • Support for guessing separator and/or quote character
  • Support for reading csv without headers

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.1')
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 in Maven Central. It is also available directly from GitHub (links below).

Maven & Ivy configuration

Latest stable

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

Latest snapshot

Downloads

GroovyCSV 1.1

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.

groovycsv's People

Contributors

antoineroux avatar gmazelier avatar xlson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.