修改文本单元格所在列的单元格格式为文本

This commit is contained in:
ThomasChant 2020-08-23 20:39:27 +08:00
parent 63cfdadc0c
commit 8ebb0e0834
1 changed files with 9 additions and 0 deletions

View File

@ -452,6 +452,15 @@ public class ExcelUtil<T>
cell.setCellValue(attr.name());
setDataValidation(attr, row, column);
cell.setCellStyle(styles.get("header"));
if (ColumnType.STRING == attr.cellType())
{
CellStyle cellStyle = cell.getCellStyle();
DataFormat wbDataFormat = wb.createDataFormat();
cellStyle.setDataFormat(wbDataFormat.getFormat("TEXT"));
} else if (ColumnType.NUMERIC == attr.cellType())
{
cell.setCellType(CellType.NUMERIC);
}
return cell;
}