Skip to content

Instantly share code, notes, and snippets.

@jonatasemidio
Last active December 17, 2015 00:59
Show Gist options
  • Save jonatasemidio/5525547 to your computer and use it in GitHub Desktop.
Save jonatasemidio/5525547 to your computer and use it in GitHub Desktop.
Criando um arquivo csv
// font: http://www.groovyexamples.org/2010/06/21/create-a-csv-file/
//For this example, let’s assume we have an array of maps as our data.
def planets = [
[id:'1',color:'red',planet:'mars',description:'Mars, the "red" planet'],
[id:'2',color:'green',planet:'neptune',description:'Neptune, the "green" planet'],
[id:'3',color:'blue',planet:'earth',description:'Earth, the "blue" planet'],
]
//Next, we can create our CSV file as follows:
def out = new File('planets.csv')
planets.each {
def row = [it.id, it.color, it.planet]
out.append row.join(',')
out.append '\n'
}
/*
Which creates a file with the following content:
1,red,mars
2,green,neptune
3,blue,earth
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment