ExcelExporter.export生成一个空工作表

时间:2015-12-22 13:14:35

标签: excel primefaces export-to-excel

我正在尝试使用primeface p:dataTable组件

以编程方式从非空数据表生成Excel工作表导出 挖了一会儿之后......我发现以下代码:

FacesContext context = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = context.getViewRoot();
UIComponent component = viewRoot.findComponent(":formName:dataTableName");
DataTable tableX = (DataTable) component;
exporter.export(context, 
            tableX, 
            tempFile.getName(), // I created a Temp file using File.createTempFile
            false, false, "UTF-8", 
            null, null);
context.responseComplete();

你能帮我找到这段代码的错误吗?为什么excel文件的大小是0KB?

非常感谢!

1 个答案:

答案 0 :(得分:0)

在primefaces中使用xls Exporter标记。

<p:dataExporter type="xls" target="tablename" fileName="your filename" />