Gat*_*het 3 java jsf primefaces
我使用primefaces 3.5,我有ap:dataTable与一些行和数据,我想将这些数据导出到xls文件或其他东西.
我用过代码:
<p:commandButton id="exportBtn" icon="ui-icon-extlink" styleClass="statisticsMenuButton" ajax="false" title="#{msg.general_export_as_xls}">
<p:dataExporter type="xls" target="cc-eventListTable-eventList" fileName="statistics"/>
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
这很好用!
我的问题是,我想在导出的文件和浏览器dataTable中有不同的单元格文本.
例如,在导出的xls文件中,我需要在浏览器数据表中进行其他日期格式化.否则浏览器单元格中的文本太长了!
我尝试仅为导出的表添加一个render ="false"和exportable ="true"的附加列.但不幸的是它不起作用!
有人知道怎么做吗?
将呈现的标记设置为false,此时它不起作用(它被报告为bug:https://github.com/primefaces-extensions/primefaces-extensions.github.com/issues/209),但是你可以用这样的css制作它:
<p:column headerText="#{msg['book.coverType']}" style="display:none;">
<h:outputText value="#{book.coverType}"/>
</p:column>
Run Code Online (Sandbox Code Playgroud)
另一种解决方案是在托管bean中添加一个post process方法,并从那里添加列.
public void postProcessXLS(Object document){log.debug("post processing Excel");
HSSFWorkbook workbook = (HSSFWorkbook) document;
addCoverType(workbook,book);
}
Run Code Online (Sandbox Code Playgroud)
你可以编写如下方法:
public void addCoverType(HSSFWorkbook workbook, List<Book> books) {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFCell cell = null;
//row 0 is the header (not automatically added by primefaces)
//add a fifth cell to each row
for (int i = 1; i < sheet.getLastRowNum() + 1; i++) {
sheet.getRow(i).createCell(4);
cell = sheet.getRow(i).getCell(4);
cell.setCellValue(book.get(i - 1).getCoverType());
}
log.debug("cover type added");
}
Run Code Online (Sandbox Code Playgroud)
如果您制作可排序列,订单也将自动受到尊重:-D
| 归档时间: |
|
| 查看次数: |
5556 次 |
| 最近记录: |