I try to remove the cell by using :
HSSFCell cell = sheet.getRow(0).getCell(i); sheet.getRow(0).removeCell(cell);
I thought this should have clear the value, but the value of the cell has just been changed from “012345678” to “0”. The cell type is always string.
Also, the cell has comment, it has not been removed neither. Then I add this statement between the two above :
It didn’t work. Is there anything I forget to do? Thanks in advance.
I don’t see anything wrong with your code. After you have removed the cell, did you remember to save the changes? The following code works fine for me.
String xlsxPath = "C:\path\test.xlsx"; Workbook wb = WorkbookFactory.create(new FileInputStream(xlsxPath)); // get first row Row row = wb.getSheetAt(0).getRow(0); // remove second cell from first row row.removeCell(row.getCell(1)); // save changes FileOutputStream fileOut = new FileOutputStream(xlsxPath); wb.write(fileOut); fileOut.close();
You can try to set the cell value to null or empty string.