3
- 需求:表头有多个单元格想设置筛选,但是区域不连续
- 实现:我使用CellWriteHandler,判定该单元格是表头且是指定的字段后,通过 Sheet sheet = context.getWriteSheetHolder().getSheet(); 和 sheet.setAutoFilter() 设置筛选
- 问题:实际导出excel后发现只有最后一个满足条件的单元个设置成功了,其他的都没有,是被覆盖了么?咱们支持这种操作么
具体的实现
public class CustomCellWriteHandler implements CellWriteHandler {
@Override
public void afterCellDispose(CellWriteHandlerContext context) {
if (!BooleanUtils.isTrue(context.getHead())) {
return;
}
Cell cell = context.getCell();
if (MAP.get(filename) == null || !MAP.get(filename).contains(cell.getStringCellValue())) {
return;
}
Sheet sheet = context.getWriteSheetHolder().getSheet();
sheet.setAutoFilter(new CellRangeAddress(cell.getRowIndex(), cell.getRowIndex(),
cell.getColumnIndex(), cell.getColumnIndex()));
}
}