[英]How export grid to excel in vaadin?
I use vaadin in my project, and i cant understend how export grid to excel. 我在项目中使用vaadin,但我不能低估导出网格如何出类拔萃。
I have: 我有:
Grid<Vlr> gridVlr = new Grid<>("Vlrs");
gridBank.setItems(VlrList); // i used ArrayList
gridBank.addColumn(Vlr::getVlrId).setCaption("VlrId");
ExportExcelComponentConfiguration<Vlr> componentConfig1
= new ExportExcelComponentConfigurationBuilder<Vlr>()
.withGrid(gridVlr)
.withVisibleProperties(new String[]{"Vlr ID"})
.withHeaderConfigs(Arrays.asList(
new ComponentHeaderConfigurationBuilder()
.withAutoFilter(true)
.withColumnKeys(new String[]{"Vlr Id"})
.build()
))
.withIntegerFormattingProperties(Arrays.asList("counter"))
.withFloatFormattingProperties(Arrays.asList(
"totalCosts",
"differenceToMin"
))
.withBooleanFormattingProperties(Arrays.asList("active"))
// .withColumnFormatters(columnFormatters)
.build();
ExportExcelSheetConfiguration<Vlr> sheetConfig1
= new ExportExcelSheetConfigurationBuilder<Vlr>()
.withReportTitle("Grid (Default)")
.withSheetName("Grid (default)")
.withComponentConfigs(Arrays.asList(componentConfig1))
.withIsHeaderSectionRequired(Boolean.TRUE)
.withDateFormat("dd-MMM-yyyy")
.build();
ExportExcelConfiguration<Vlr> config
= new ExportExcelConfigurationBuilder<Vlr>()
.withGeneratedBy("Roman")
.withSheetConfigs(Arrays.asList(sheetConfig1))
.build();
ExportToExcel exportToExcel = new ExportToExcel(ExportType.XLSX, null);
Button buttonExport = new Button("Export to Excel", clickEvent -> {
exportToExcel.export();
});
layout.addComponent(buttonExport);
What's my mistake? 我怎么了 Maybe there is a simpler solution?
也许有一个更简单的解决方案?
There is documentation about file download in book of vaadin here . 有一个关于在vaadin的书文件下载的文件在这里 。 You are missing download "link" from your button.
您缺少按钮上的下载“链接”。
Steps to download a file from button click are following 以下是通过单击按钮下载文件的步骤
createResosurce
method write xlsx file on the server createResosurce
方法中,在服务器上写入xlsx文件 StreamResource
to the file. StreamResource
到文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.