RajeysGS
RajeysGS

Reputation: 47

Not getting Required excel coulmn types using java

Am trying to create 6 fields of a class as 6 columns in an excel.

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("NEW EXCEL");
Row row = sheet.createRow(rownum++); 
cell = row.createCell(4);
//"PAY Amount" field
cell.setCellValue(Double.parseDouble("100.00"));
cell.setCellType(Cell.CELL_TYPE_NUMERIC);

Consider the above pseudo code, if I ran the whole program, am getting generated with excel where PAY Amount coulmn has 100.00 but when I click on that cell value, right click --> format cells, it shows like "General" category but i wanted it to be "Numeric category.

Let me know if you reuire further details. Using poi 3.11 jar.

Upvotes: 0

Views: 40

Answers (1)

Michal
Michal

Reputation: 1010

First create cell style with needed format

XSSFWorkbook wb = //your workbook
XSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setDataFormat(1);

and later set the style to your cells

cell.setCellStyle(supplierCellStyle);

here is list of all built in styles: https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html

and remember to reuse cell style.

Upvotes: 1

Related Questions