Skip to content

Instantly share code, notes, and snippets.

@jorgeuriarte
Last active January 11, 2017 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgeuriarte/85bb9f60f805e9df35b89be045dc7712 to your computer and use it in GitHub Desktop.
Save jorgeuriarte/85bb9f60f805e9df35b89be045dc7712 to your computer and use it in GitHub Desktop.
@Grab(group='org.modelcatalogue', module='spreadsheet-builder-poi', version='0.3.1')
@Grab(group='commons-codec', module='commons-codec', version='1.10')
@GrabExclude('org.codehaus.groovy:groovy-all')
import org.modelcatalogue.spreadsheet.api.Cell
import org.modelcatalogue.spreadsheet.builder.poi.PoiSpreadsheetBuilder
import org.modelcatalogue.spreadsheet.query.api.SpreadsheetCriteria
import org.modelcatalogue.spreadsheet.query.poi.PoiSpreadsheetCriteria
File file = new File('report.xlsx')
def data = [campaign: 'Campaña de prueba',
brand: 'Coca-Cola Company',
distribution: [Influencers:35, 'Facebook Posts':50, 'Twitter Posts':75, 'Instagram Posts':3],
engagement: ['Total engagements': 2343, 'Engagements FB': 1232, 'Engagements TW': 1100, 'Engagements IN': 111],
influencers: [[name:'Jorge Uriarte', profile: 'jorgeuriarte', network:'Twitter', followers: 1134],
[name:'Fernando Niwes', profile: 'fniwes', network: 'Twitter', followers: 23434]]
]
PoiSpreadsheetBuilder.INSTANCE.build {
sheet('KasitokoReport') {
row {
cell {
png image from 'http://ssp.kasitoko.com/images/kasitoko_logo@2x.png'
}
}
row 3, {
cell ''
cell {
value "Campaign name:"
width auto
style {
font {
make bold
}
}
}
cell {
value data.campaign
width 25
}
}
row {
cell ''
cell {
value "Brand:"
width auto
style {
font {
make bold
}
}
}
cell data.brand
}
row {
cell ''
cell {
value 'Dates'
width auto
style {
font {
make bold
}
}
}
cell "De Pascuas a Ramos"
}
row {
cell ''
cell {
value 'Purchase Order'
width auto
style {
font {
make bold
}
}
}
cell "PO-2344546"
}
row 8, {
cell ''
cell {
value 'Distribution'
style {
font {
make bold, underline
}
}
}
}
data.distribution.each { k,v ->
row {
cell 3, {
value k
}
cell v
}
}
row {}
row {
cell {}
cell {
value 'Engagement'
style {
font {
make bold, underline
}
}
}
}
data.engagement.each { k,v ->
row {
cell 3, {
value k
}
cell v
}
}
row {}
row {
cell {}
cell {
value 'POSTS'
style {
font {
make bold, underline
}
}
}
}
row {
style { font { make bold } }
cell {}
cell {}
cell 'Influencer full name'
cell 'Profile'
cell 'Network'
cell 'Followers'
}
(1..200).each {
data.influencers.each { inf ->
row {
cell 2, {}
cell inf.name
cell {
value inf.profile
width 15
}
cell inf.network
cell {
value inf.followers
style { format "#,##0" }
}
}
}
}
}
} writeTo file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment