| | |
| | | public class DocumentMaterialsVo { |
| | | |
| | | |
| | | @Excel(name="序号") |
| | | @Excel(name="序号", height = 10,width=10) |
| | | private Long num; |
| | | @Excel(name = "文件编号") |
| | | @Excel(name = "文件编号", height = 10, width=15) |
| | | private String documentNumber; |
| | | @Excel(name = "编任者") |
| | | @Excel(name = "责任者", height = 10, width=10) |
| | | private String creator; |
| | | @Excel(name = "文件题名") |
| | | @Excel(name = "文件题名", height = 20) |
| | | |
| | | private String title; |
| | | |
| | | @JsonFormat(pattern = "yyyy-MM-dd") |
| | | |
| | | @Excel(name = "日期", width = 30, dateFormat = "yyyy-MM-dd") |
| | | @Excel(name = "日期", width = 10, dateFormat = "yyyy-MM-dd", height = 10) |
| | | |
| | | private Date date; |
| | | @Excel(name = "页号") |
| | | @Excel(name = "页号", height = 10,width = 10) |
| | | |
| | | private Long pageNumber; |
| | | @Excel(name = "备注") |
| | | @Excel(name = "备注", height = 20) |
| | | private String remarks; |
| | | |
| | | @Excel(name = "档号") |
| | | @Excel(name = "档号", height = 10) |
| | | private String recordId; |
| | | @Excel(name = "公开属性") |
| | | @Excel(name = "公开属性", height = 10) |
| | | private String publicity; |
| | | |
| | | |
| | |
| | | import com.ruoyi.common.annotation.Excel; |
| | | import com.ruoyi.common.annotation.NumberFormatHandler; |
| | | import lombok.Data; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | |
| | | import java.util.Date; |
| | | |
| | |
| | | this.title = title; |
| | | } |
| | | |
| | | @Excel(name="序号") |
| | | @Excel(name="序号", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private int num; |
| | | @Excel(name="档号") |
| | | @Excel(name="档号",headerColor = IndexedColors.RED,width = 15, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String recordId; |
| | | @Excel(name = "文件材料序号", handler = NumberFormatHandler.class) |
| | | @Excel(name = "文件材料序号", width=10,headerColor = IndexedColors.RED,handler = NumberFormatHandler.class, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long fileNumber; |
| | | |
| | | |
| | | @Excel(name = "文件编号") |
| | | @Excel(name = "文件编号",width=9,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String documentNumber; |
| | | |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "编任者") |
| | | @Excel(name = "责任者",width=8,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String creator; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "文件题名") |
| | | @Excel(name = "文件题名",headerColor = IndexedColors.RED, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String title; |
| | | |
| | | /** $column.columnComment */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd") |
| | | @Excel(name = "日期", width = 30, dateFormat = "yyyy-MM-dd") |
| | | @Excel(name = "日期", width = 10, headerColor = IndexedColors.BLACK,dateFormat = "yyyy-MM-dd", headerBackgroundColor = IndexedColors.WHITE) |
| | | private Date date; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "页号", handler = NumberFormatHandler.class) |
| | | @Excel(name = "页号", width = 10,headerColor = IndexedColors.RED,handler = NumberFormatHandler.class, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long pageNumber; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "页次") |
| | | @Excel(name = "页次", width = 10,headerColor = IndexedColors.RED, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long pageOrder; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "所处阶段") |
| | | @Excel(name = "所处阶段", width = 10,headerColor = IndexedColors.RED, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String stage; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "公开属性") |
| | | @Excel(name = "公开属性", width = 10,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String publicity; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "是否为附件附图") |
| | | @Excel(name = "是否为附件附图", width = 10,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String isAttachment; |
| | | |
| | | /** $column.columnComment */ |
| | |
| | | private String isDiagram; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "保管期限") |
| | | @Excel(name = "保管期限", width = 10,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String retentionPeriod; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "密级", readConverterExp = "该页另存=普通,普通=普通,内部用图=内部用图,内部用途=内部用途,秘密=秘密") |
| | | @Excel(name = "密级", width = 10,headerColor = IndexedColors.BLACK,readConverterExp = "该页另存=普通,普通=普通,内部用图=内部用图,内部用途=内部用途,秘密=秘密", headerBackgroundColor = IndexedColors.WHITE) |
| | | private String securityLevel; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "是否涉密及敏感信息") |
| | | @Excel(name = "是否涉密及敏感信息",headerColor = IndexedColors.BLACK, width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String isSensitive; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "是否注销") |
| | | @Excel(name = "是否注销" ,headerColor = IndexedColors.BLACK,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String isCanceled; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "格式") |
| | | @Excel(name = "格式",headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String format; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "幅面") |
| | | @Excel(name = "幅面", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String sizeType; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "水平分辨率") |
| | | @Excel(name = "水平分辨率",headerColor = IndexedColors.RED, width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long horizontalResolution; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "垂直分辨率") |
| | | @Excel(name = "垂直分辨率",headerColor = IndexedColors.RED, width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long verticalResolution; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "宽度") |
| | | @Excel(name = "宽度", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long width; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "高度") |
| | | @Excel(name = "高度", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Long height; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "大小") |
| | | @Excel(name = "大小", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private Double fileSize; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "附件及历史发文号") |
| | | @Excel(name = "附件及历史发文号",headerColor = IndexedColors.BLACK, width = 10, headerBackgroundColor = IndexedColors.WHITE) |
| | | private String attachmentHistoryNumbers; |
| | | |
| | | /** $column.columnComment */ |
| | | @Excel(name = "备注") |
| | | //@Excel(name = "备注", width = 10) |
| | | private String remarks; |
| | | public String getUrl() { |
| | | return url; |
| | |
| | | |
| | | |
| | | for(int i = 0; i < ids.length; i++) { |
| | | |
| | | // 获取文件的保存位置,读取数据库, |
| | | DocumentMaterials documentMaterials = new DocumentMaterials(); |
| | | documentMaterials.setRecordId(ids[i]); |
| | |
| | | ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(ids[i]); |
| | | |
| | | String adir = aIV.getInquiryNumber() + " " + aIV.getRecordId(); |
| | | System.out.println(fna + adir); |
| | | System.out.println(fna+adir); |
| | | zos.putNextEntry(new ZipEntry(fna + adir + "/")); |
| | | |
| | | //在里面添加文件 |
| | |
| | | System.out.println(filePath+"0009999999999"); |
| | | response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); |
| | | FileUtils.setAttachmentResponseHeader(response, realFileName); |
| | | // response.addHeader("Content-Disposition", "attachment;filename=fileName" + ".xls"); |
| | | |
| | | FileUtils.writeBytes(filePath, response.getOutputStream()); |
| | | |
| | | } |
| | |
| | | /** |
| | | * 是否允许内容换行 |
| | | */ |
| | | public boolean wrapText() default false; |
| | | public boolean wrapText() default true; |
| | | |
| | | /** |
| | | * 设置只能选择不能输入的列内容. |
| | |
| | | .append("utf-8''") |
| | | .append(percentEncodedFileName); |
| | | |
| | | |
| | | response.setCharacterEncoding("UTF-8"); |
| | | response.setHeader("content-Type", "application/vnd.ms-excel"); |
| | | response.setHeader("Content-Disposition", |
| | | "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8")); |
| | | // response.addHeader("Content-Disposition", "attachment;filename=fileName" + ".xls"); |
| | | response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename"); |
| | | response.setHeader("Content-disposition", contentDispositionValue.toString()); |
| | | response.setHeader("download-filename", percentEncodedFileName); |
| | |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | style.setFillForegroundColor(excel.headerBackgroundColor().index); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | // 设置表头自动换行 |
| | | style.setWrapText(true); |
| | | Font headerFont = wb.createFont(); |
| | | headerFont.setFontName("Arial"); |
| | | headerFont.setFontHeightInPoints((short) 10); |
| | | headerFont.setBold(true); |
| | | headerFont.setBold(false); |
| | | headerFont.setColor(excel.headerColor().index); |
| | | style.setFont(headerFont); |
| | | // 设置表格头单元格文本形式 |
| | |
| | | } |
| | | else if (ColumnType.IMAGE == attr.cellType()) |
| | | { |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1); |
| | | String propertyValue = Convert.toStr(value); |
| | | if (StringUtils.isNotEmpty(propertyValue)) |
| | | { |
| | |
| | | Cell cell = null; |
| | | try |
| | | { |
| | | // 设置行高 |
| | | row.setHeight(maxHeight); |
| | | // 设置行高为自动调整 |
| | | row.setHeight((short) -1); |
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. |
| | | if (attr.isExport()) |
| | | { |
| | |
| | | */ |
| | | public void createWorkbook() |
| | | { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | this.wb = new HSSFWorkbook(); |
| | | this.sheet = wb.createSheet(); |
| | | wb.setSheetName(0, sheetName); |
| | | this.styles = createStyles(wb); |
| | |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | // if (Files.exists(Paths.get(imagePath))) { |
| | | // byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath)); |
| | | // 将byte数组转换成inputstream,以便插入到Excel中 |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 5), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 5), |
| | | cell.getRow().getRowNum() + 1); |
| | | // 计算居中位置 |
| | | int col1 = 1; // 中间列 |
| | |
| | | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderBottom(BorderStyle.THIN); |
| | | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | // 设置自动换行 |
| | | style.setWrapText(true); |
| | | Font dataFont = wb.createFont(); |
| | | dataFont.setFontName("Arial"); |
| | | dataFont.setFontHeightInPoints((short) 10); |
| | |
| | | headerFont.setBold(true); |
| | | headerFont.setColor(IndexedColors.WHITE.getIndex()); |
| | | style.setFont(headerFont); |
| | | // 表头也设置自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("header", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | |
| | | totalFont.setFontName("Arial"); |
| | | totalFont.setFontHeightInPoints((short) 10); |
| | | style.setFont(totalFont); |
| | | // 总计行也设置自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("total", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.LEFT); |
| | | // 左对齐样式也设置自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data1", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | // 居中对齐样式也设置自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data2", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.RIGHT); |
| | | // 右对齐样式也设置自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data3", style); |
| | | |
| | | return styles; |
| | |
| | | } else if (Excel.ColumnType.NUMERIC == attr.cellType()) { |
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | } else if (Excel.ColumnType.IMAGE == attr.cellType()) { |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | cell.getRow().getRowNum() + 1); |
| | | String imagePath = Convert.toStr(value); |
| | | if (StringUtils.isNotEmpty(imagePath)) { |
| | |
| | | // 如果设置了提示信息则鼠标放上去提示. |
| | | if (StringUtils.isNotEmpty(attr.prompt())) { |
| | | // 这里默认设了2-101列提示. |
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | } |
| | | // 如果设置了combo属性则本列只能选择不能输入 |
| | | if (attr.combo().length > 0) { |
| | | // 这里默认设了2-101列只能选择不能输入. |
| | | setXSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | setHSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | } |
| | | } |
| | | |
| | |
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { |
| | | Cell cell = null; |
| | | try { |
| | | // 设置行高 |
| | | row.setHeight(maxHeight); |
| | | // 设置行高为自动调整 |
| | | row.setHeight((short) -1); |
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. |
| | | if (attr.isExport()) { |
| | | // 创建cell |
| | | cell = row.createCell(column); |
| | | // attr.align(); |
| | | // int align = attr.align().value; |
| | | // cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : ""))); |
| | | // 设置单元格样式 |
| | | HorizontalAlignment align = attr.align(); |
| | | String styleKey = "data"; |
| | | if (align == HorizontalAlignment.LEFT) { |
| | | styleKey = "data1"; |
| | | } else if (align == HorizontalAlignment.CENTER) { |
| | | styleKey = "data2"; |
| | | } else if (align == HorizontalAlignment.RIGHT) { |
| | | styleKey = "data3"; |
| | | } |
| | | cell.setCellStyle(styles.get(styleKey)); |
| | | |
| | | // 用于读取对象中的属性 |
| | | Object value = getTargetValue(vo, field, attr); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置 POI XSSFSheet 单元格提示 |
| | | * 设置 POI HSSFSheet 单元格提示 |
| | | * |
| | | * @param sheet 表单 |
| | | * @param promptTitle 提示标题 |
| | |
| | | * @param firstCol 开始列 |
| | | * @param endCol 结束列 |
| | | */ |
| | | public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | DataValidationConstraint constraint = helper.createCustomConstraint("DD1"); |
| | |
| | | * @param endCol 结束列 |
| | | * @return 设置好的sheet. |
| | | */ |
| | | public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | // 加载下拉列表内容 |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist); |
| | |
| | | // 数据有效性对象 |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | // 处理Excel兼容性问题 |
| | | if (dataValidation instanceof XSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } else { |
| | | if (dataValidation instanceof HSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | |
| | | sheet.addValidationData(dataValidation); |
| | |
| | | * 创建一个工作簿 |
| | | */ |
| | | public void createWorkbook() { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | this.wb = new HSSFWorkbook(); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFRichTextString; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFRichTextString; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | Cell cell = row.createCell(6); |
| | | |
| | | // 设置图片大小和位置 |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2), |
| | | cell.getRow().getRowNum() + 1); |
| | | // 计算居中位置 |
| | | // int col1 = 0; // 中间列 |
| | |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font headerFont = wb.createFont(); |
| | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | Font totalFont = wb.createFont(); |
| | | totalFont.setFontName("Arial"); |
| | | totalFont.setFontHeightInPoints((short) 10); |
| | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.LEFT); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data1", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data2", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.RIGHT); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data3", style); |
| | | |
| | | return styles; |
| | |
| | | } else if (Excel.ColumnType.NUMERIC == attr.cellType()) { |
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | } else if (Excel.ColumnType.IMAGE == attr.cellType()) { |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | cell.getRow().getRowNum() + 1); |
| | | String imagePath = Convert.toStr(value); |
| | | if (StringUtils.isNotEmpty(imagePath)) { |
| | |
| | | // 如果设置了提示信息则鼠标放上去提示. |
| | | if (StringUtils.isNotEmpty(attr.prompt())) { |
| | | // 这里默认设了2-101列提示. |
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | } |
| | | // 如果设置了combo属性则本列只能选择不能输入 |
| | | if (attr.combo().length > 0) { |
| | | // 这里默认设了2-101列只能选择不能输入. |
| | | setXSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | setHSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | } |
| | | } |
| | | |
| | |
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { |
| | | Cell cell = null; |
| | | try { |
| | | // 设置行高 |
| | | row.setHeight(maxHeight); |
| | | // 设置行高为自动调整 |
| | | row.setHeight((short) -1); |
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. |
| | | if (attr.isExport()) { |
| | | // 创建cell |
| | | cell = row.createCell(column); |
| | | // attr.align(); |
| | | // int align = attr.align().value; |
| | | // cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : ""))); |
| | | // 设置单元格样式 |
| | | HorizontalAlignment align = attr.align(); |
| | | String styleKey = "data"; |
| | | if (align == HorizontalAlignment.LEFT) { |
| | | styleKey = "data1"; |
| | | } else if (align == HorizontalAlignment.CENTER) { |
| | | styleKey = "data2"; |
| | | } else if (align == HorizontalAlignment.RIGHT) { |
| | | styleKey = "data3"; |
| | | } |
| | | cell.setCellStyle(styles.get(styleKey)); |
| | | |
| | | // 用于读取对象中的属性 |
| | | Object value = getTargetValue(vo, field, attr); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置 POI XSSFSheet 单元格提示 |
| | | * 设置 POI HSSFSheet 单元格提示 |
| | | * |
| | | * @param sheet 表单 |
| | | * @param promptTitle 提示标题 |
| | |
| | | * @param firstCol 开始列 |
| | | * @param endCol 结束列 |
| | | */ |
| | | public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | DataValidationConstraint constraint = helper.createCustomConstraint("DD1"); |
| | |
| | | * @param endCol 结束列 |
| | | * @return 设置好的sheet. |
| | | */ |
| | | public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | // 加载下拉列表内容 |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist); |
| | |
| | | // 数据有效性对象 |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | // 处理Excel兼容性问题 |
| | | if (dataValidation instanceof XSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } else { |
| | | if (dataValidation instanceof HSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | |
| | | sheet.addValidationData(dataValidation); |
| | |
| | | * 创建一个工作簿 |
| | | */ |
| | | public void createWorkbook() { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | this.wb = new HSSFWorkbook(); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | //sheet.setColumnWidth(1, 15 * 256); // 第二列宽度15字符 |
| | | //sheet.setColumnWidth(2, 25 * 256); // 第三列宽度25字符 // 设置第一列宽度为20个字符 |
| | | |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2), |
| | | cell.getRow().getRowNum() + 1); |
| | | // 计算居中位置 |
| | | // int col1 = 0; // 中间列 |
| | |
| | | Font font = wb.createFont(); |
| | | font.setBold(true); |
| | | style.setFont(font); |
| | | style.setWrapText(true); // 设置自动换行 |
| | | style.setWrapText(true); // 设置自动换行 |
| | | cell.setCellStyle(style); |
| | | cell.setCellValue(tits[i]); |
| | | Cell cel = row.createCell(1); |
| | |
| | | if(i==3) |
| | | { |
| | | row = sheet.createRow(8); |
| | | // 设置行高为自动调整 |
| | | row.setHeight((short) -1); |
| | | // row.setHeight((short) 30); |
| | | row.setHeightInPoints(40); // 设置行高为20磅 |
| | | row = sheet.createRow(9); |
| | |
| | | //sheet.setColumnWidth(1, 15 * 256); // 第二列宽度15字符 |
| | | //sheet.setColumnWidth(2, 25 * 256); // 第三列宽度25字符 // 设置第一列宽度为20个字符 |
| | | |
| | | ClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell1.getColumnIndex()), cell1.getRow().getRowNum(), (short) (cell1.getColumnIndex() +2), |
| | | ClientAnchor anchor1 = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell1.getColumnIndex()), cell1.getRow().getRowNum(), (short) (cell1.getColumnIndex() +2), |
| | | cell1.getRow().getRowNum() + 1); |
| | | // 计算居中位置 |
| | | //// 设置图片大小和位置 |
| | |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font headerFont = wb.createFont(); |
| | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | Font totalFont = wb.createFont(); |
| | | totalFont.setFontName("Arial"); |
| | | totalFont.setFontHeightInPoints((short) 10); |
| | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.LEFT); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data1", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data2", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.RIGHT); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data3", style); |
| | | |
| | | return styles; |
| | |
| | | } else if (Excel.ColumnType.NUMERIC == attr.cellType()) { |
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | } else if (Excel.ColumnType.IMAGE == attr.cellType()) { |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | cell.getRow().getRowNum() + 1); |
| | | String imagePath = Convert.toStr(value); |
| | | if (StringUtils.isNotEmpty(imagePath)) { |
| | |
| | | // 如果设置了提示信息则鼠标放上去提示. |
| | | if (StringUtils.isNotEmpty(attr.prompt())) { |
| | | // 这里默认设了2-101列提示. |
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | } |
| | | // 如果设置了combo属性则本列只能选择不能输入 |
| | | if (attr.combo().length > 0) { |
| | | // 这里默认设了2-101列只能选择不能输入. |
| | | setXSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | setHSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | } |
| | | } |
| | | |
| | |
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { |
| | | Cell cell = null; |
| | | try { |
| | | // 设置行高 |
| | | row.setHeight((short) 2000); |
| | | // 设置行高为自动调整 |
| | | row.setHeight((short) -1); |
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. |
| | | if (attr.isExport()) { |
| | | // 创建cell |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置 POI XSSFSheet 单元格提示 |
| | | * 设置 POI HSSFSheet 单元格提示 |
| | | * |
| | | * @param sheet 表单 |
| | | * @param promptTitle 提示标题 |
| | |
| | | * @param firstCol 开始列 |
| | | * @param endCol 结束列 |
| | | */ |
| | | public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | DataValidationConstraint constraint = helper.createCustomConstraint("DD1"); |
| | |
| | | * @param endCol 结束列 |
| | | * @return 设置好的sheet. |
| | | */ |
| | | public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | // 加载下拉列表内容 |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist); |
| | |
| | | // 数据有效性对象 |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | // 处理Excel兼容性问题 |
| | | if (dataValidation instanceof XSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } else { |
| | | if (dataValidation instanceof HSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | |
| | | sheet.addValidationData(dataValidation); |
| | |
| | | * 创建一个工作簿 |
| | | */ |
| | | public void createWorkbook() { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | this.wb = new HSSFWorkbook(); |
| | | } |
| | | |
| | | /** |
| | |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.ss.util.CellRangeAddressList; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFClientAnchor; |
| | | import org.apache.poi.xssf.usermodel.XSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor; |
| | | import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font headerFont = wb.createFont(); |
| | |
| | | style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | Font totalFont = wb.createFont(); |
| | | totalFont.setFontName("Arial"); |
| | | totalFont.setFontHeightInPoints((short) 10); |
| | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.LEFT); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data1", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data2", style); |
| | | |
| | | style = wb.createCellStyle(); |
| | | style.cloneStyleFrom(styles.get("data")); |
| | | style.setAlignment(HorizontalAlignment.RIGHT); |
| | | // 设置单元格内容自动换行 |
| | | style.setWrapText(true); |
| | | styles.put("data3", style); |
| | | |
| | | return styles; |
| | |
| | | } else if (Excel.ColumnType.NUMERIC == attr.cellType()) { |
| | | cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value)); |
| | | } else if (Excel.ColumnType.IMAGE == attr.cellType()) { |
| | | ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), |
| | | cell.getRow().getRowNum() + 1); |
| | | String imagePath = Convert.toStr(value); |
| | | if (StringUtils.isNotEmpty(imagePath)) { |
| | |
| | | // 如果设置了提示信息则鼠标放上去提示. |
| | | if (StringUtils.isNotEmpty(attr.prompt())) { |
| | | // 这里默认设了2-101列提示. |
| | | setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column); |
| | | } |
| | | // 如果设置了combo属性则本列只能选择不能输入 |
| | | if (attr.combo().length > 0) { |
| | | // 这里默认设了2-101列只能选择不能输入. |
| | | setXSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | setHSSFValidation(sheet, attr.combo(), 1, 100, column, column); |
| | | } |
| | | } |
| | | |
| | |
| | | public Cell addCell(Excel attr, Row row, T vo, Field field, int column) { |
| | | Cell cell = null; |
| | | try { |
| | | // 设置行高 |
| | | row.setHeight(maxHeight); |
| | | // 设置行高为自动调整 |
| | | row.setHeight((short) -1); |
| | | // 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列. |
| | | if (attr.isExport()) { |
| | | // 创建cell |
| | | cell = row.createCell(column); |
| | | // attr.align(); |
| | | // int align = attr.align().value; |
| | | // cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : ""))); |
| | | // 设置单元格样式 |
| | | HorizontalAlignment align = attr.align(); |
| | | String styleKey = "data"; |
| | | if (align == HorizontalAlignment.LEFT) { |
| | | styleKey = "data1"; |
| | | } else if (align == HorizontalAlignment.CENTER) { |
| | | styleKey = "data2"; |
| | | } else if (align == HorizontalAlignment.RIGHT) { |
| | | styleKey = "data3"; |
| | | } |
| | | cell.setCellStyle(styles.get(styleKey)); |
| | | |
| | | // 用于读取对象中的属性 |
| | | Object value = getTargetValue(vo, field, attr); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置 POI XSSFSheet 单元格提示 |
| | | * 设置 POI HSSFSheet 单元格提示 |
| | | * |
| | | * @param sheet 表单 |
| | | * @param promptTitle 提示标题 |
| | |
| | | * @param firstCol 开始列 |
| | | * @param endCol 结束列 |
| | | */ |
| | | public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, |
| | | int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | DataValidationConstraint constraint = helper.createCustomConstraint("DD1"); |
| | |
| | | * @param endCol 结束列 |
| | | * @return 设置好的sheet. |
| | | */ |
| | | public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) { |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | // 加载下拉列表内容 |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist); |
| | |
| | | // 数据有效性对象 |
| | | DataValidation dataValidation = helper.createValidation(constraint, regions); |
| | | // 处理Excel兼容性问题 |
| | | if (dataValidation instanceof XSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(true); |
| | | dataValidation.setShowErrorBox(true); |
| | | } else { |
| | | if (dataValidation instanceof HSSFDataValidation) { |
| | | dataValidation.setSuppressDropDownArrow(false); |
| | | dataValidation.setShowErrorBox(true); |
| | | } |
| | | |
| | | sheet.addValidationData(dataValidation); |
| | |
| | | * 创建一个工作簿 |
| | | */ |
| | | public void createWorkbook() { |
| | | this.wb = new SXSSFWorkbook(500); |
| | | this.wb = new HSSFWorkbook(); |
| | | } |
| | | |
| | | /** |