环境:
-
jsf 2.2
-
primefaces 6.1
-
wilfly 10
我正在尝试使用primefaces的dataExporter将dataTable导出到excel,但首先
<p:commandButton id="btnExpExcel"
alt="#{msgs.inv_exportinvoices}"
ajax="false">
<p:dataExporter type="xls" target="lstFactures"
fileName="invoices"/>
</p:commandButton>
<p:dataTable id="lstFactures" var="inv"
...
选项1
我是xls pex的。83.2但我们使用,作为十进制,而不是。
...
<p:column headerText="#{msgs.total}">
<h:outputText value="#{inv.total}">
<f:convertNumber locale="#{localeBean.locale}"/>
</h:outputText>
</p:column>
...
选项2
我是xls pex的。83,2但excel将其处理为文本而不是数字
...
<p:column headerText="#{msgs.total}">
<h:outputText value="#{inv.total}" />
</p:column>
...
**选项3**带
public void postProcessXLS(对象文档){
HSSF工作手册wb=(HSSF工作手册)文件;
HSSF表=wb。getSheetAt(0);
HSSFRow收割台;
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
int ind = 0;
for (int row = 0; row < invoices.size() + 1; row++) {
header = sheet.getRow(row);
for (int col = 0; col < header.getPhysicalNumberOfCells(); col++) {
...
}
if (col == 5) {
HSSFCell cell = header.getCell(col);
//Total is a float
cell.setCellValue(invoices.get(ind).getTotal());
ind++;
}
}
}
}
}
我还尝试exportFunction=“\{inv.total}”,但出现了某种错误exportFunction=“\{inv.total}”:找不到方法。。。
xls中的内容如下