如何使用 p:dataExporter 导出正确类型的数字?
How can I export numbers in the correct type using p:dataExporter?
我正在使用 PrimeFaces dataExporter
将我的数据表导出到 Excel 文件。问题是数字导出为文本。
如何将我的数字导出为整数和双精度数?
<p:column headerText="net_usd_sale">
<h:outputText value="#{dizgi.net_usd_sale}" />
</p:column>
<p:column style="text-align: center" exportable="false">
<f:facet name="header">
<h:outputText value="Details" />
</f:facet>
<h:graphicImage value="/resources/images/details.png" alt="details image" />
</p:column>
</p:dataTable>
<h3>Export Page Data Only</h3>
<h:commandLink>
<p:graphicImage library="images" name="excel.png" width="24" />
<p:dataExporter type="xls" target="tbl" fileName="dizgi" pageOnly="true"/>
</h:commandLink>
</h:form>
</html>
有一个选项可以自定义您的数据导出器
<h:commandLink id="excel">
<p:graphicImage name="/demo/images/excel.png" />
<p:dataExporter type="xls" target="tbl" fileName="cars"
postProcessor="#{customizedDocumentsView.postProcessXLS}" />
</h:commandLink>
在post 过程事件中,您可以操作您的工作簿。检查这个 link Primefaces DataExporter - Customized Documents
public void postProcessXLS(Object document) {
HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow header;
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
int ind=0;
for(int j=0;j<dizgi.size()+1;j++) {
header = sheet.getRow(j);
for(int i=0; i < header.getPhysicalNumberOfCells();i++) {
if(j==0){
HSSFCell cell = header.getCell(i);
cell.setCellStyle(cellStyle);
}
else{
if(i==2){
HSSFCell cell = header.getCell(i);
cell.setCellValue(dizgi.get(ind).getTicket_sold());
}
if(i==3 ){
HSSFCell cell = header.getCell(i);
cell.setCellValue(dizgi.get(ind).getNet_usd_sale());
ind++;
}
}
}
}
}
> Ok I solved it,thanks.
我正在使用 PrimeFaces dataExporter
将我的数据表导出到 Excel 文件。问题是数字导出为文本。
如何将我的数字导出为整数和双精度数?
<p:column headerText="net_usd_sale">
<h:outputText value="#{dizgi.net_usd_sale}" />
</p:column>
<p:column style="text-align: center" exportable="false">
<f:facet name="header">
<h:outputText value="Details" />
</f:facet>
<h:graphicImage value="/resources/images/details.png" alt="details image" />
</p:column>
</p:dataTable>
<h3>Export Page Data Only</h3>
<h:commandLink>
<p:graphicImage library="images" name="excel.png" width="24" />
<p:dataExporter type="xls" target="tbl" fileName="dizgi" pageOnly="true"/>
</h:commandLink>
</h:form>
</html>
有一个选项可以自定义您的数据导出器
<h:commandLink id="excel">
<p:graphicImage name="/demo/images/excel.png" />
<p:dataExporter type="xls" target="tbl" fileName="cars"
postProcessor="#{customizedDocumentsView.postProcessXLS}" />
</h:commandLink>
在post 过程事件中,您可以操作您的工作簿。检查这个 link Primefaces DataExporter - Customized Documents
public void postProcessXLS(Object document) {
HSSFWorkbook wb = (HSSFWorkbook) document;
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow header;
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
int ind=0;
for(int j=0;j<dizgi.size()+1;j++) {
header = sheet.getRow(j);
for(int i=0; i < header.getPhysicalNumberOfCells();i++) {
if(j==0){
HSSFCell cell = header.getCell(i);
cell.setCellStyle(cellStyle);
}
else{
if(i==2){
HSSFCell cell = header.getCell(i);
cell.setCellValue(dizgi.get(ind).getTicket_sold());
}
if(i==3 ){
HSSFCell cell = header.getCell(i);
cell.setCellValue(dizgi.get(ind).getNet_usd_sale());
ind++;
}
}
}
}
}
> Ok I solved it,thanks.