All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jameskleeh.excel.ExcelBuilder.groovy Maven / Gradle / Ivy

There is a newer version: 0.4.4
Show newest version
package com.jameskleeh.excel

import groovy.transform.CompileStatic
import org.apache.poi.xssf.usermodel.XSSFWorkbook

/**
 * The main class used to start building an excel document
 */
@CompileStatic
class ExcelBuilder {

    static void output(OutputStream outputStream, @DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Workbook) Closure callable) {
        XSSFWorkbook wb = build(callable)
        wb.write(outputStream)
    }

    static XSSFWorkbook build(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Workbook) Closure callable) {
        XSSFWorkbook wb = new XSSFWorkbook()
        callable.resolveStrategy = Closure.DELEGATE_FIRST
        callable.delegate = new Workbook(wb)
        if (callable.maximumNumberOfParameters == 1) {
            callable.call(wb)
        } else {
            callable.call()
        }
        wb
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy