Reputation: 1943
Does anyone know a good library written in java providing a fluid wrapper around Apache POI?
The Ugly Duckling entry on the POI case studies page (last entry) refers to something like this.
Upvotes: 2
Views: 1397
Reputation: 21
Have a look on this repo nambach/ExcelUtil. It supports reading and writing Excel files in declarative way.
public class Main {
static final Style HEADER_STYLE = Style
.builder()
.fontColorInHex("#ffffff")
.backgroundColorInHex("#191970")
.border(BorderSide.FULL)
.horizontalAlignment(HorizontalAlignment.LEFT)
.build();
static final Style OTHER_STYLES...
static final DataTemplate<Book> BOOK_TEMPLATE = DataTemplate
.fromClass(Book.class)
.includeFields("isbn", "title", "author")
.column(c -> c.title("Category")
.transform(book -> book.getCategory().getName())) // derive new column
.column(c -> c.field("rating")
.conditionalStyle(book -> book.getRating() > 4 ? // styles with conditions
HIGH_RATE : null))
.config(cf -> cf.startAtCell("A2")
.autoSizeColumns(true)
.headerStyle(HEADER_STYLE)
.dataStyle(DATA_STYLE)
.conditionalRowStyle(book -> book.getTitle() // selective styling
.contains("Harry Potter") ? FAVORITE_ONE : null));
public static void main(String[] args) {
List<Book> books = dataSource.fetchData();
InputStream stream = BOOK_TEMPLATE.writeData(books);
FileUtil.writeToDisk(".../books.xlsx", stream, true);
}
}
Upvotes: 2
Reputation: 5119
I was looking for a DSL wrapper that can generate XLSX files. The Subtlib POI library can only generate XLS (BIFF) files. I forked Subtlib POI to write XLSX files: https://github.com/bekoeppel/poi-ooxml
Upvotes: 1