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

de.peterbecker.xls.Workbook.kt Maven / Gradle / Ivy

Go to download

This is a number of extensions and additional classes to make handling XLS files easier in Kotlin.

There is a newer version: 0.7
Show newest version
package de.peterbecker.xls

import org.apache.poi.ss.SpreadsheetVersion
import org.apache.poi.ss.usermodel.Name
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.util.AreaReference
import org.apache.poi.ss.util.CellReference

fun Workbook.writeToRange(name: String, rows: Iterator>): AreaReference {
    val range = this.getName(name) ?: throw NamedRangeNotFound(name)
    return writeToRange(range, rows)
}

fun Workbook.writeToRange(range: Name, rows: Iterator>): AreaReference {
    val ref = AreaReference(range.refersToFormula, SpreadsheetVersion.EXCEL2007)
    val sheet = this.getSheet(range.sheetName)
    val newArea = sheet.writeToArea(ref, rows)
    range.refersToFormula = newArea.formatAsString()
    return newArea
}

fun Workbook.writeToRange(name: String, rows: Iterable>) =
        writeToRange(name, rows.iterator())




© 2015 - 2024 Weber Informatics LLC | Privacy Policy