Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Cellstyle of a org.apache.poi.ss.usermodel.Cell to boolean

I would like to write a boolean-value into an excel-cell, but instead of setting the cellStyle to "logic" the cellStyle will become "number" instead.

private void writeToDocument(XSSFWorkbook workbook) {
    Sheet sheet = workbook.createSheet("testSheet");
    Row row = sheet.createRow(0);
    Cell cell = row.createCell(0);
    cell.setCellValue(true);
}

I already tryied

CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat([short s]);
cell.setCellStyle(cellStyle);

but no short s between 0 and 49 did the job.

like image 221
Korbinian Reffler Avatar asked Apr 06 '18 09:04

Korbinian Reffler


1 Answers

When appropriate overloaded version of setCellValue is used the cell types will be assigned automatically, for example

cell.setCellValue(true);
System.out.println(cell.getCellType());

prints BOOLEAN

Checked on org.apache.poi:poi:4.1.1

like image 57
edwgiz Avatar answered Oct 21 '22 03:10

edwgiz