【发布时间】:2015-06-30 08:03:01
【问题描述】:
在我的另一个应用程序中,我有一个带有动态列的数据表。我的代码应该将数据表内容导出为 excel 格式。我拥有的代码适用于具有固定列数的数据表。但如果它在动态列中,它不会带来标题行。我浏览了更多网站,他们建议使用带有标签的虚拟列。我也试过了。但无法将标题带入excel。其他excel内容显示正常。
我的代码是:
Xhtml代码:
<p:dataTable id="rosterviewtab" var="data" value="#{dtRosterView.rostertab}" >
<p:columnGroup type="header">
<p:row>
<p:column headerText="" />
<p:column style="display:none">
<f:facet name="header"> #{dtRosterView.dates} </f:facet>
</p:column>
<ui:repeat value="#{dtRosterView.dates}" var="dates">
<p:column headerText="#{dates}" exportable="false" />
</ui:repeat>
</p:row>
</p:columnGroup>
<p:column>
<h:outputText value="#{data.slot_noresources}" />
</p:column>
<p:column>
<h:outputText value="#{data.datecol1}" />
</p:column>
<p:column>
<h:outputText value="#{data.datecol2}" />
</p:column>
</p:dataTable>
<h:panelGrid columns="2" cellpadding="5">
<p:commandButton value="Export To Excel" style="font-size:11px;width:120px;height:40px" immediate="true" ajax="false" >
<p:dataExporter type="xls" target="rosterviewtab" fileName="RosterView" postProcessor="#{dtRosterView.postProcessXLS}" update="@form" />
</p:commandButton>
在我的 Bean 类中:
public void postProcessXLS(Object document)
{ HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFSheet sheet = wb.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
System.out.println("cell value -->"+ cell.getStringCellValue());
cell.setCellValue(cell.getStringCellValue().toUpperCase());
}
}
}
【问题讨论】:
标签: jsf primefaces datatable