我在我的项目中使用vaadin,我无法了解出口网格如何出类拔萃。
我有:
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);
我的错是什么? 也许有一个更简单的解决方案?
答案 0 :(得分:0)
在vaadin here的书中有关于文件下载的文档。您缺少从按钮下载“链接”。
从按钮点击下载文件的步骤如下:
createResosurce
方法中,在服务器上编写xlsx文件StreamResource
提供给文件。