Beginner
Beginner

Reputation: 875

Excel Formatting in Java

I am using Apache POI jars to write excel in Java.

For the below code(referred from other websites), it uses HSSFCellUtil.java class from poi-contrib.jar. This jar doesn't come in the latest release of poi-3.14.jar.

I am getting compile time error at HSSFCellUtil.DATA_FORMAT. Can anyone suggest me the alternative for Excel Formatting.

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

Upvotes: 0

Views: 1878

Answers (2)

Ico
Ico

Reputation: 1

I use org.apache.poi.ss.util.CellUtil and it works

Replace

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

with this

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

Upvotes: 0

Vicky Thakor
Vicky Thakor

Reputation: 3916

Try using org.apache.poi.ss.util.CellUtil

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

Upvotes: 1

Related Questions