单元格填充长数字字符串,会自动从文本变为常规,然后再打开会发现这串数字变成科学计数法显示了,这时候需要强制设为文本类型,如果不好使请确认一下之后的逻辑是否再次修改了CellStyle:
DataFormat dataFormat = workbook.createDataFormat();
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(dataFormat.getFormat("@"));
cell.setCellStyle(cellStyle);
解除单元格保护:
cellStyle.setLocked(false);
单元格编辑时背景变成一片黑色,需要移除填充样式:
cellStyle.setFillPattern(FillPatternType.NO_FILL);
设置字体为红色(一般为错误信息):
Font font = workbook.createFont();
font.setColor(Font.COLOR_RED);
cellStyle.setFont(font);
设置红色边框(一般为错误提示):
BorderStyle borderStyle = BorderStyle.MEDIUM;
cellStyle.setBorderTop(borderStyle);
cellStyle.setBorderBottom(borderStyle);
cellStyle.setBorderLeft(borderStyle);
cellStyle.setBorderRight(borderStyle);
short borderColor = IndexedColors.RED.getIndex();
cellStyle.setTopBorderColor(borderColor);
cellStyle.setBottomBorderColor(borderColor);
cellStyle.setLeftBorderColor(borderColor);
cellStyle.setRightBorderColor(borderColor);