Pre Merge pull request !199 from 想象之中/master

This commit is contained in:
想象之中 2020-08-23 20:49:39 +08:00 committed by Gitee
commit 0babeb41ad
1 changed files with 34 additions and 38 deletions

View File

@ -19,23 +19,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataValidation;
import org.apache.poi.ss.usermodel.DataValidationConstraint;
import org.apache.poi.ss.usermodel.DataValidationHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
@ -468,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;
}
@ -482,6 +475,9 @@ public class ExcelUtil<T>
{
if (ColumnType.STRING == attr.cellType())
{
CellStyle cellStyle = cell.getCellStyle();
DataFormat wbDataFormat = wb.createDataFormat();
cellStyle.setDataFormat(wbDataFormat.getFormat("TEXT"));
cell.setCellType(CellType.STRING);
cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix());
}