MetadataConsulting/spreadsheet-builder


Spreadsheet Builder

License: Apache-2.0

Language: Groovy

Keywords: builder, builder-pattern, builders, excel, exceldatareader, excelgenerator, excelparser, excelreader, excelwriter, groovy, microsoft, spreadsheet, spreadsheet-manipulations


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.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('spreadsheet.xlsx')

PoiSpreadsheetBuilder.INSTANCE.build {                                                  // <1>
    sheet('Sample') {                                                                   // <2>
        row {                                                                           // <3>
            cell 'A'                                                                    // <4>
            cell 'B'
            cell 'C'
        }
        row {
            cell 1
            cell 2
            cell 3
        }
    }
} writeTo file                                                                          // <5>

SpreadsheetQuery query = PoiSpreadsheetCriteria.FACTORY.forFile(file)                      // <6>

Collection  cells = query.query {                                                 // <7>
    sheet {                                                                             // <8>
        row {                                                                           // <9>
            cell {
                value 'B'                                                               // <10>
            }
        }
    }
}

assert cells.size() == 1
assert cells.first().value == 'B'
  1. Build new spreadsheet based on Apache POI

  2. Create new sheet with the name Sample

  3. Create new row

  4. Create new cell

  5. Write the spreadsheet to the file

  6. Create new spreadsheet query for given file

  7. Start a query

  8. Query any sheet

  9. Query any row

  10. Query all cells containing value 'B'

Acknowledgement

This project is inspired by Groovy Document Builder

Project Statistics

Sourcerank 6
Repository Size 1.99 MB
Stars 44
Forks 10
Watchers 13
Open issues 6
Dependencies 4
Contributors 1
Tags 8
Created
Last updated
Last pushed

Top Contributors See all

Vladimir Orany

Recent Tags See all

0.1.12 January 04, 2016
0.1.11 October 22, 2015
0.1.10 October 15, 2015
0.1.9 October 14, 2015
0.1.8 October 13, 2015
0.1.7 October 13, 2015
0.1.5 October 12, 2015
0.1.3 October 12, 2015

Interesting Forks See all

dsl-builders/spreadsheet
Spreadsheet Builder
Java - Last pushed - 7 stars - 1 forks

Something wrong with this page? Make a suggestion

Last synced: 2017-02-22 19:09:17 UTC

Login to resync this repository