Directory

← Back

Exporter

A simple tool for exporting data from Grid to Excel or CSV. Exporter 1.x.x for Vaadin 7, Exporter 2.x.x for Vaadin 8, Exporter 3.x.x for Vaadin 10+

Author

Rating

Popularity

800+
Exporter.exportAsExcel(grid));
Exporter.exportAsCSV(grid))

A typical use case is to let user download the generated file, an Anchor component can be used for such a purpose.

Vaadin 10+

new Anchor(new StreamResource("my-excel.xlsx", Exporter.exportAsExcel(grid)), "Download As Excel");

Vaadin 8

Button downloadAsExcel = new Button("Download As Excel");
StreamResource excelStreamResource = new StreamResource((StreamResource.StreamSource) () -> Exporter.exportAsExcel(grid), "my-excel.xlsx");
FileDownloader excelFileDownloader = new FileDownloader(excelStreamResource);
excelFileDownloader.extend(downloadAsExcel);

Use instructions

Each to be exported column should have a key, and the key should be a property name. A key will be generated automatically if you are also passing the class in the Grid constructor parameter, e.g.

Grid<Person> grid = new Grid<>(Person.class);

Otherwise, you need to set the key manually. e.g.

Grid<Person> grid = new Grid<>();
grid.addColumn(Person::getEmail).setKey("email");

Exporter works as using reflection to read property from each item, a column without a valid key will be ignored.

Exporter 1 for Vaadin 7 works a bit differently. It's a Vaadin Button to download the exported files and it's based on Vaadin Container. Code Example on how to use Exporter 1

ExcelExporter excelExporter = new ExcelExporter();
excelExporter.setDateFormat("yyyy-MM-dd");
excelExporter.setTableToBeExported(sampleTable);
excelExporter.setCaption("Export to Excel");
layout.addComponent(excelExporter);

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Added .xlsx support, also makes .xlsx the default file when calling Export.exportAsExcel(). To export as .xls file, call Export.exportAsXls()

Released
2019-05-10
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 10+
Vaadin 11+ in 3.0.0
Vaadin 8.0+ in 2.0.2
Vaadin 7.0+ in 1.0.1
Browser
Browser Independent

Vaadin Add-on Directory

Find open-source widgets, add-ons, themes, and integrations for your Vaadin application. Vaadin Add-on Directory
The channel for finding, promoting, and distributing Vaadin add-ons.
Online