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+

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);

Install

Link to this version
ExperimentalReleased 10 May 2019Apache License 2.0
Framework Support
Vaadin platform 10+
Also supported:
Vaadin 7 (1.0.1)Vaadin 8 (2.0.2)
Browser Compatibility
6
7
8
9
Install with
Release notes - Version 3.0.1

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