Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number stored as text warning in excel using POI

I am getting Number stored as text warning for the created excel file using POI. I am trying to display percentage. This question discusses the same, but it's for python. Can some one please suggest me how to avoid this in java using POI?

Below are the lines where I get this warning.

workbook= new XSSFWorkbook();
sh1 = wb.createSheet("Data Sheet");
    cell = row.createCell(3);
    cell.setCellValue(37 + "%");

Based on Gagravarr answer I did it this way.

XSSFDataFormat df = workbook.createDataFormat();
                    CellStyle cs = wb.createCellStyle();
                    cs.setDataFormat(df.getFormat("%"));
                    cell.setCellValue(0.37);
                    cell.setCellStyle(cs);

But it just shows up as 0.37 with no warning now, not 37%.

like image 679
rick Avatar asked Feb 21 '14 04:02

rick


People also ask

How do I remove the warning in Excel using Apache POI in java?

When I generate Excel, it will give me green indication with warning "Number Stored as Text" or "Text date with 2-digit year" on cell. I want to remove that warning. I found that from excel we can flag a cell as 'ignore error', to ignore the warning.

How do I wrap text in Excel using Apache POI?

setWrapText(true); cell. setCellStyle(cellStyle); Saving a file generated with the above code and viewing it in Microsoft Excel will show multiline text in a cell.


1 Answers

    if(NumberUtils.isDigits(text)){
        titleCell.setCellValue(Integer.parseInt(text));
    }else{
        titleCell.setCellValue(text);
    }
like image 184
Thamarai Selvan Dhandapani Avatar answered Sep 21 '22 04:09

Thamarai Selvan Dhandapani