Search code examples
javaapache-poipoi-hssfhssf

HSSF. Clear the cell


sheet.setColumnWidth(13,(short)0); totally different

row.removeCell(13); doesn't work too.

What I should use for this goal?(delete cell)


Solution

  • If you want to clear the data of a cell:

    Option 1: set the cell's value to null. The advantage of this option is you don't need to get the cell style, alignment, font style, etc. for that cell.

    row.getCell(13).setCellValue(null); 
    Cell cell13 = cell.getCell(13);
    

    Option 2: remove cell. When you take cell13 again, it will return null. That's why you need to create the cell and also the style.

     row.removeCell(13);
     Cell cell13 = cell.getCell(13);