更换prompt名称

dep_wangsr
RuoYi 6 years ago committed by Limy
parent 4da966328f
commit 372a56e49e

@ -9,8 +9,6 @@ import com.ruoyi.common.reflect.ReflectUtils;
import com.ruoyi.common.support.Convert; import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import org.apache.poi.hssf.usermodel.DVConstraint;
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;
@ -20,7 +18,6 @@ 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 java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -329,7 +326,7 @@ public class ExcelUtil<T>
if (attr.combo().length > 0) if (attr.combo().length > 0)
{ {
// 这里默认设了2-101列只能选择不能输入. // 这里默认设了2-101列只能选择不能输入.
setHSSFValidation(sheet, attr.combo(), 1, 100, i, i); setXSSFValidation(sheet, attr.combo(), 1, 100, i, i);
} }
} }
if (Type.EXPORT.equals(type)) if (Type.EXPORT.equals(type))
@ -422,11 +419,11 @@ public class ExcelUtil<T>
Object value = getTargetValue(vo, field, attr); Object value = getTargetValue(vo, field, attr);
String dateFormat = attr.dateFormat(); String dateFormat = attr.dateFormat();
String readConverterExp = attr.readConverterExp(); String readConverterExp = attr.readConverterExp();
if (StringUtils.isNotEmpty(dateFormat)) if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
{ {
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value)); cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
} }
else if (StringUtils.isNotEmpty(readConverterExp)) else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
{ {
cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp)); cell.setCellValue(convertByExp(String.valueOf(value), readConverterExp));
} }
@ -440,40 +437,15 @@ public class ExcelUtil<T>
} }
catch (Exception e) catch (Exception e)
{ {
log.error("导出Excel失败{}", e.getMessage()); log.error("导出Excel失败{}", e);
} }
} }
} }
} }
/**
*
*
* @param sheet sheet.
* @param promptTitle
* @param promptContent
* @param firstRow
* @param endRow
* @param firstCol
* @param endCol
* @return sheet.
*/
public static Sheet setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol)
{
// 构造constraint对象
DVConstraint constraint = DVConstraint.createCustomFormulaConstraint("DD1");
// 四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
// 数据有效性对象
HSSFDataValidation dataValidationView = new HSSFDataValidation(regions, constraint);
dataValidationView.createPromptBox(promptTitle, promptContent);
sheet.addValidationData(dataValidationView);
return sheet;
}
/** /**
* POI XSSFSheet * POI XSSFSheet
*
* @param sheet * @param sheet
* @param promptTitle * @param promptTitle
* @param promptContent * @param promptContent
@ -482,11 +454,13 @@ public class ExcelUtil<T>
* @param firstCol * @param firstCol
* @param endCol * @param endCol
*/ */
public static void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow, int firstCol, int endCol) { public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
DataValidationHelper dvHelper = sheet.getDataValidationHelper(); int firstCol, int endCol)
DataValidationConstraint constraint = dvHelper.createCustomConstraint("*"); {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol); CellRangeAddressList regions = new CellRangeAddressList(firstRow, endRow, firstCol, endCol);
DataValidation dataValidation = dvHelper.createValidation(constraint, regions); DataValidation dataValidation = helper.createValidation(constraint, regions);
dataValidation.createPromptBox(promptTitle, promptContent); dataValidation.createPromptBox(promptTitle, promptContent);
dataValidation.setShowPromptBox(true); dataValidation.setShowPromptBox(true);
sheet.addValidationData(dataValidation); sheet.addValidationData(dataValidation);
@ -503,8 +477,7 @@ public class ExcelUtil<T>
* @param endCol * @param endCol
* @return sheet. * @return sheet.
*/ */
public static Sheet setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol)
int endCol)
{ {
DataValidationHelper helper = sheet.getDataValidationHelper(); DataValidationHelper helper = sheet.getDataValidationHelper();
// 加载下拉列表内容 // 加载下拉列表内容
@ -525,7 +498,6 @@ public class ExcelUtil<T>
} }
sheet.addValidationData(dataValidation); sheet.addValidationData(dataValidation);
return sheet;
} }
/** /**

@ -5,7 +5,6 @@ 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.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -19,7 +18,7 @@ public class SysUser extends BaseEntity
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 用户ID */ /** 用户ID */
@Excel(name = "用户序号", prompt = "用户流水号") @Excel(name = "用户序号", prompt = "用户号")
private Long userId; private Long userId;
/** 部门ID */ /** 部门ID */

Loading…
Cancel
Save