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+
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);
Links
Compatibility
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
fixed a bug: forgot cvs file extention
- Released
- 2013-03-01
- Maturity
- EXPERIMENTAL
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 7.0+
- Vaadin 11+ in 3.0.0
- Vaadin 10+ in 3.0.1
- Vaadin 8.0+ in 2.0.2
- Browser
- Internet Explorer
- Internet Explorer
- Internet Explorer
- Firefox
- Opera
- Safari
- Google Chrome
- Internet Explorer
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+Online Demo
Source Code
Issue Tracker
Exporter version 0.0.2
Support PDF export
- use ExcelExporter to export Excel file
- use PdfExporter to export PDF file
Exporter version 0.0.3
fixed a bug in previous release, which generates the same file even through the table changes.
Exporter version 0.0.3.1
updated maven pom, added itextpdf and apache poi dependencies
Exporter version 0.0.5
Added CSV Support
Exporter version 0.0.5.1
Now Exporter has a default constructor, and allows you to set the data to be exported later with setTableToBeExported(Table table) and setContainerToBeExported(Container container)
Exporter version 0.0.5.2
fixed a bug: forgot cvs file extention
Exporter version 0.0.5.3
Now you can set the date format and/or locale through setDateFormat and setLocale
Exporter version 0.0.5.4
Now you can set the download file name with setDownloadFileName method of Exporter
Exporter version 0.0.5.5
fixed the pom issue
Exporter version 0.0.6
mavenize
Exporter version 0.0.7
removed pdf feature.
Exporter version 1.0.0
For Vaadin 7
Exporter version 2.0.0
For Vaadin 8
Exporter version 3.0.0
For Vaadin platform (10+)
Exporter version 2.0.1
Add support for .xlsx file, and makes .xlsx the default file when calling Exporter.exportAsExcel().
To export as .xls file, call Exporter.exportAsXls().
Exporter 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()
Exporter version 2.0.2
Added ExporterOption so that users can have a custom header (custom name, upper case)
```
ExporterOption exporterOption = new ExporterOption();
exporterOption.getColumnOption("name").columnName("My Name").toUpperCase();
exporterOption.getColumnOption("email").columnName("My Email");
exporterOption.getColumnOption("age").toUpperCase();
StreamResource excelStreamResourceWithCustomHeader = new StreamResource((StreamResource.StreamSource) () -> Exporter.exportAsExcel(grid, exporterOption), "my-excel-with-cutom-header.xlsx");
FileDownloader excelFileDownloaderWithCustomHeader = new FileDownloader(excelStreamResourceWithCustomHeader);
excelFileDownloaderWithCustomHeader.extend(downloadAsExcelWithCustomHeader);
```
Exporter version 1.0.1
Fix v7 caching issue and some improvements, see this [pull request](https://github.com/haiwan/Exporter/pull/32).
Big thanks to [Anthony Baldarelli](https://github.com/mobileWMS) for the contribution.