修复@Excel注解 prompt 属性使用报错

master
stickdream 6 years ago committed by Limy
parent 8d8498d88e
commit 4da966328f

@ -1,59 +1,36 @@
package com.ruoyi.common.utils.poi; package com.ruoyi.common.utils.poi;
import java.io.File; import com.ruoyi.common.annotation.Excel;
import java.io.FileOutputStream; import com.ruoyi.common.annotation.Excel.Type;
import java.io.IOException; import com.ruoyi.common.base.AjaxResult;
import java.io.InputStream; import com.ruoyi.common.config.Global;
import java.io.OutputStream; import com.ruoyi.common.exception.BusinessException;
import java.lang.reflect.Field; import com.ruoyi.common.reflect.ReflectUtils;
import java.lang.reflect.Method; import com.ruoyi.common.support.Convert;
import java.math.BigDecimal; import com.ruoyi.common.utils.DateUtils;
import java.text.DecimalFormat; import com.ruoyi.common.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.poi.hssf.usermodel.DVConstraint; import org.apache.poi.hssf.usermodel.DVConstraint;
import org.apache.poi.hssf.usermodel.HSSFDataValidation; import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFFont; import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined; import org.apache.poi.hssf.util.HSSFColor.HSSFColorPredefined;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.*;
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.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.util.CellRangeAddressList; import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFDataValidation; import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.Type; import java.io.*;
import com.ruoyi.common.base.AjaxResult; import java.lang.reflect.Field;
import com.ruoyi.common.config.Global; import java.lang.reflect.Method;
import com.ruoyi.common.exception.BusinessException; import java.math.BigDecimal;
import com.ruoyi.common.reflect.ReflectUtils; import java.text.DecimalFormat;
import com.ruoyi.common.support.Convert; import java.util.*;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
/** /**
* Excel * Excel
* *
* @author ruoyi * @author ruoyi
*/ */
public class ExcelUtil<T> public class ExcelUtil<T>
@ -120,7 +97,7 @@ public class ExcelUtil<T>
/** /**
* excellist * excellist
* *
* @param input * @param input
* @return * @return
*/ */
@ -131,7 +108,7 @@ public class ExcelUtil<T>
/** /**
* excellist * excellist
* *
* @param sheetName * @param sheetName
* @param input * @param input
* @return * @return
@ -261,7 +238,7 @@ public class ExcelUtil<T>
/** /**
* listexcel * listexcel
* *
* @param list * @param list
* @param sheetName * @param sheetName
* @return * @return
@ -274,7 +251,7 @@ public class ExcelUtil<T>
/** /**
* listexcel * listexcel
* *
* @param sheetName * @param sheetName
* @return * @return
*/ */
@ -286,7 +263,7 @@ public class ExcelUtil<T>
/** /**
* listexcel * listexcel
* *
* @return * @return
*/ */
public AjaxResult exportExcel() public AjaxResult exportExcel()
@ -346,7 +323,7 @@ public class ExcelUtil<T>
if (StringUtils.isNotEmpty(attr.prompt())) if (StringUtils.isNotEmpty(attr.prompt()))
{ {
// 这里默认设了2-101列提示. // 这里默认设了2-101列提示.
setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, i, i); setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, i, i);
} }
// 如果设置了combo属性则本列只能选择不能输入 // 如果设置了combo属性则本列只能选择不能输入
if (attr.combo().length > 0) if (attr.combo().length > 0)
@ -399,7 +376,7 @@ public class ExcelUtil<T>
/** /**
* excel * excel
* *
* @param index * @param index
* @param row * @param row
* @param cell * @param cell
@ -471,7 +448,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param sheet sheet. * @param sheet sheet.
* @param promptTitle * @param promptTitle
* @param promptContent * @param promptContent
@ -495,9 +472,29 @@ public class ExcelUtil<T>
return sheet; return sheet;
} }
/**
* POI XSSFSheet
* @param sheet
* @param promptTitle
* @param promptContent
* @param firstRow
* @param endRow
* @param firstCol
* @param endCol
*/
public static void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper dvHelper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = dvHelper.createCustomConstraint("*");
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
DataValidation dataValidation = dvHelper.createValidation(constraint, regions);
dataValidation.createPromptBox(promptTitle, promptContent);
dataValidation.setShowPromptBox(true);
sheet.addValidationData(dataValidation);
}
/** /**
* ,. * ,.
* *
* @param sheet sheet. * @param sheet sheet.
* @param textlist * @param textlist
* @param firstRow * @param firstRow
@ -533,7 +530,7 @@ public class ExcelUtil<T>
/** /**
* 0=,1=,2= * 0=,1=,2=
* *
* @param propertyValue * @param propertyValue
* @param converterExp * @param converterExp
* @return * @return
@ -562,7 +559,7 @@ public class ExcelUtil<T>
/** /**
* =0,=1,=2 * =0,=1,=2
* *
* @param propertyValue * @param propertyValue
* @param converterExp * @param converterExp
* @return * @return
@ -600,7 +597,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param filename * @param filename
*/ */
public String getAbsoluteFile(String filename) public String getAbsoluteFile(String filename)
@ -616,7 +613,7 @@ public class ExcelUtil<T>
/** /**
* bean * bean
* *
* @param vo * @param vo
* @param field * @param field
* @param excel * @param excel
@ -647,7 +644,7 @@ public class ExcelUtil<T>
/** /**
* get * get
* *
* @param o * @param o
* @param name * @param name
* @return value * @return value
@ -708,7 +705,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param sheetNameSheet * @param sheetNameSheet
* @param sheetNo sheet * @param sheetNo sheet
* @param index * @param index
@ -729,7 +726,7 @@ public class ExcelUtil<T>
/** /**
* *
* *
* @param row * @param row
* @param column * @param column
* @return * @return

@ -1,12 +1,13 @@
package com.ruoyi.system.domain; package com.ruoyi.system.domain;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.Excel.Type; import com.ruoyi.common.annotation.Excel.Type;
import com.ruoyi.common.base.BaseEntity; import com.ruoyi.common.base.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
import java.util.List;
/** /**
* sys_user * sys_user
@ -18,7 +19,7 @@ public class SysUser extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 用户ID */ /** 用户ID */
@Excel(name = "用户序号") @Excel(name = "用户序号", prompt = "用户流水号")
private Long userId; private Long userId;
/** 部门ID */ /** 部门ID */

Loading…
Cancel
Save