0

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)"));
0

2 Answers 2

1

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"));
Sign up to request clarification or add additional context in comments.

Comments

0

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"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.