2016-06-01 14 views
0

Ich verwende Apache POI-Jars, um Excel in Java zu schreiben.Excel-Formatierung in Java

Für den folgenden Code (von anderen Websites verwiesen), verwendet es die Klasse HSSFCellUtil.java von poi-contrib.jar. Dieses Glas kommt nicht in der neuesten Version von poi-3.14.jar.

Ich bekomme Kompilierzeit Fehler bei HSSFCellUtil.DATA_FORMAT. Kann mir jemand die Alternative zur Excel-Formatierung vorschlagen?

HSSFCellUtil.setCellStyleProperty(cell, workbook, 
        HSSFCellUtil.DATA_FORMAT, 
        format.getFormat("($#,##0.00);($#,##0.00)")); 

Antwort

1

Versuchen Sie es mit org.apache.poi.ss.util.CellUtil

DataFormat dataFormat = workbook.createDataFormat(); 
CellUtil.setCellStyleProperty(cell, workbook, CellUtil.DATA_FORMAT, dataFormat.getFormat("$#,##0.00;$#,##0.00"));