Skip to content

blackg00se/spreadsheet-builder

 
 

Repository files navigation

Groovy Spreadsheet Builder

Spreadsheet builder provides convenient way how to create MS Excel OfficeOpenXML Documents (XSLX) focus not only on content side but also on easy styling.

Getting Started

Following example creates the basic spreadsheet with two rows and three columns.

@Grab(group='org.modelcatalogue', module='spreadsheet-builder-poi', version='{version}')
// fixes bugs on Groovy 2.4.x
@Grab(group='commons-codec', module='commons-codec', version='1.10')
@GrabExclude('org.codehaus.groovy:groovy-all')

import org.modelcatalogue.builder.spreadsheet.poi.PoiSpreadsheetBuilder

def builder = new PoiSpreadsheetBuilder()                                                   // <1>

File file = new File('spreadsheet.xlsx')

file.withOutputStream { out ->
    builder.build(out) {                                                                    // <2>
        sheet('Sample') {                                                                   // <3>
            row {                                                                           // <4>
                cell 'A'                                                                    // <5>
                cell 'B'
                cell 'C'
            }
            row {
                cell 1
                cell 2
                cell 3
            }
        }
    }
}
  1. Create new spreadsheet builder based on Apache POI (currently the only implementation provided)

  2. Build new spreadsheet and write it to the output stream

  3. Create new sheet with the name Sample

  4. Create new row

  5. Create new cell

Acknowledgement

This project is inspired by Groovy Document Builder

About

Spreadsheet Builder

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 63.3%
  • Java 36.7%