I want to remove the cell content but keeping its style but it's always remove the style and content. Here's my code:
private static void RefreshReport(String sheetName, String resultColumn) {
try {
InputStream inp = new FileInputStream(getExcelFile());
Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheet(sheetName);
int colResult = getColumnResult(sheet, resultColumn);
int rowStart = getRowResult(sheet, resultColumn);
int rowEnd = Math.max(20, sheet.getLastRowNum());
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
Row r = sheet.getRow(rowNum);
if (r != null) {
Cell cell = r.createCell(colResult);
if (cell.getCellType() != Cell.CELL_TYPE_BLANK) {
CellStyle cs = wb.createCellStyle();
cs = cell.getCellStyle();
r.removeCell(cell);
cell = r.createCell(colResult);
cell.setCellStyle(cs);
}
}
}
FileOutputStream fileOut = new FileOutputStream(getExcelFile());
wb.write(fileOut);
fileOut.close();
inp.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Any help would be great.