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

700+
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

Fix v7 caching issue and some improvements, see this pull request.

Big thanks to Anthony Baldarelli for the contribution.

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

Compatibility

Framework
Vaadin 7.0+
Vaadin 11+ in 3.0.0
Vaadin 10+ in 3.0.0
Vaadin 8.0+ in 2.0.0
Browser
Browser Independent

Exporter - Vaadin Add-on Directory

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 - Vaadin Add-on Directory
``` 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 grid = new Grid<>(Person.class); ``` Otherwise, you need to set the key manually. e.g. ``` Grid 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); ```
Online