Open Negri001 opened 5 months ago
public class CustomCellWriteHeightConfig extends AbstractRowHeightStyleStrategy { /**
默认高度 */ private static final Integer DEFAULT_HEIGHT = 300;
@Override protected void setHeadColumnHeight(Row row, int relativeRowIndex) { }
@Override protected void setContentColumnHeight(Row row, int relativeRowIndex) { Iterator cellIterator = row.cellIterator(); if (!cellIterator.hasNext()) { return; }
// 默认为 1行高度 Integer maxHeight = 1; while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getCellTypeEnum()) { case STRING: if (cell.getStringCellValue().indexOf("\n") != -1) { int length = cell.getStringCellValue().split("\n").length; maxHeight = Math.max(maxHeight, length); } break; default: break; } } row.setHeight((short) (maxHeight * DEFAULT_HEIGHT));
} }EasyExcel.registerWriteHandler(new CustomCellWriteWeightConfig()) .registerWriteHandler(new CustomCellWriteHeightConfig()); 以上代码AbstractRowHeightStyleStrategy 类中进入方法也调用但是没有执行我重写的方法,我设置自定义列宽没有问题。 easyExcel的版本是2.2.7
public class CustomCellWriteHeightConfig extends AbstractRowHeightStyleStrategy { /**
默认高度 */ private static final Integer DEFAULT_HEIGHT = 300;
@Override protected void setHeadColumnHeight(Row row, int relativeRowIndex) { }
@Override protected void setContentColumnHeight(Row row, int relativeRowIndex) { Iterator cellIterator = row.cellIterator();
if (!cellIterator.hasNext()) {
return;
} |
} }EasyExcel.registerWriteHandler(new CustomCellWriteWeightConfig()) .registerWriteHandler(new CustomCellWriteHeightConfig()); 以上代码AbstractRowHeightStyleStrategy 类中进入方法也调用但是没有执行我重写的方法,我设置自定义列宽没有问题。 easyExcel的版本是2.2.7