List of usage examples for org.apache.poi.hssf.usermodel HSSFDataValidation createPromptBox
public void createPromptBox(String title, String text)
From source file:com.sccl.attech.common.utils.excel.ExportExcel.java
License:Open Source License
/** * ?//from w ww .j a v a 2 s .c om * @param row * @param column ? * @param val * @param align ??1?23?? * @return ? */ public Cell addCellStyle(Row row, int column, Object val, int align, Class<?> fieldType) { Cell cell = row.createCell(column); CellStyle style = styles.get("data" + (align >= 1 && align <= 3 ? align : "")); style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style.setAlignment(HSSFCellStyle.ALIGN_LEFT); style.setWrapText(true); try { if (val == null) { cell.setCellValue(""); } else if (val instanceof String) { cell.setCellValue((String) val); } else if (val instanceof Integer) { cell.setCellValue((Integer) val); } else if (val instanceof Long) { cell.setCellValue((Long) val); } else if (val instanceof Double) { cell.setCellValue((Double) val); } else if (val instanceof Float) { cell.setCellValue((Float) val); } else if (val instanceof Date) { DataFormat format = wb.createDataFormat(); style.setDataFormat(format.getFormat("yyyy-MM-dd")); cell.setCellValue((Date) val); } else { if (fieldType != Class.class) { cell.setCellValue((String) fieldType.getMethod("setValue", Object.class).invoke(null, val)); } else { cell.setCellValue((String) Class .forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(), "fieldtype." + val.getClass().getSimpleName() + "Type")) .getMethod("setValue", Object.class).invoke(null, val)); } } } catch (Exception ex) { log.info("Set cell value [" + row.getRowNum() + "," + column + "] error: " + ex.toString()); cell.setCellValue(val.toString()); } if (column == 8) { CellRangeAddressList regions = new CellRangeAddressList(25, 25, 8, 8); // ? DVConstraint constraint = DVConstraint .createExplicitListConstraint(new String[] { "2", "3", "" }); // HSSFDataValidation data_validation = new HSSFDataValidation(regions, constraint); // sheet data_validation.createErrorBox("Error", "Error"); data_validation.createPromptBox("", null); sheet.addValidationData(data_validation); } cell.setCellStyle(style); return cell; }