Export TreeGrid to Excel

Hi,

Is there any add-on available that exports TreeGrid to Excel and supports Vaadin 8?

Thanks

This one claims to be one (I haven’t tried it): https://vaadin.com/directory/component/excel-exporter - give it a try.

-Olli

Thanks Olli - that was the first thing that I tried. But looks like the add-on has not been updated to support recent versions.
it does not work - throws couple of unsupported exceptions. The reviews that the people have left on the add-on mention similar issues that are being faced by them.

Do you know of any other alternatives?

I checked the code of that add-on. I think it is fairly straightforward to modify it to support TreeGrid.

This constructor needs to be changed to get list of items via data communictor

protected Integer addGridToExcelSheet(final Grid<BEANTYPE> grid, final XSSFWorkbook myWorkBook, Sheet sheet,
int rowNum, final ExportExcelSheetConfiguration<BEANTYPE> sheetConfiguration,
final ExportExcelComponentConfiguration<BEANTYPE> componentConfiguration) {
Collection<BEANTYPE> items;
if (grid.getDataProvider() instanceof ListDataProvider) {
items = ((ListDataProvider<BEANTYPE>) grid.getDataProvider()).getItems();
} else {
throw new UnsupportedOperationException("dataProvider " + grid.getDataProvider()
.getClass() + " of grid is not supported");
}
return addGridToExcelSheet(items, myWorkBook, sheet, rowNum, sheetConfiguration, componentConfiguration);
}

Proably like

protected Integer addGridToExcelSheet(final Grid<BEANTYPE> grid, final XSSFWorkbook myWorkBook, Sheet sheet,
int rowNum, final ExportExcelSheetConfiguration<BEANTYPE> sheetConfiguration,
final ExportExcelComponentConfiguration<BEANTYPE> componentConfiguration) {
Collection<BEANTYPE> items;

items = ((ListDataProvider<BEANTYPE>) grid.getDataCommunicator().fetchItemsWithRange(0, grid.getDataCommunicator().getDataProviderSize());

return addGridToExcelSheet(items, myWorkBook, sheet, rowNum, sheetConfiguration, componentConfiguration);
}

Then it should work on any data provider. The current version of the ExcelExporter does not work with lazy providers either. Note, if the data source is big, the list of items would be huge and this will be heavy operation.