poi删除空单元格
2023-01-30 本文已影响0人
musk
/**
* 处理单元格为BLANK标志位
*/
public static final String CELL_BLANK_VALUE_FLAG = "^^^^SET_EXCEL_CELL_BLANK^^^^";
// 删除空处理
for (Row cells : sheet) {
for (Cell cell : cells) {
if(null == cell || cell.getCellType() == CellType.BLANK
|| cell.getCellType() == CellType.FORMULA
){
continue;
}
CellType cellType = cell.getCellType();
if(cellType.getCode() == CellType.STRING.getCode()) {
//设置单元格类型
// if (cellType.getCode() != CellType.STRING.getCode()) {
// cell.setCellType(CellType.STRING);
// }
// String s1 = cell.getStringCellValue();
// System.out.println(cell.getStringCellValue());
if (cell.getStringCellValue().equals(CELL_BLANK_VALUE_FLAG)) {
// System.out.println(cell.getStringCellValue());
cell.setBlank();
cell.setCellType(CellType.BLANK);
} else {
// cell.setCellType(cellType);
// String v = cell.getStringCellValue();
// if (!s1.equals(v)) {
// System.out.println(s1 + "=>" + v);
// }
//
// cell.setCellValue(s1);
}
}
}
}