|
|
@ -1,55 +1,32 @@
|
|
|
|
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相关处理
|
|
|
@ -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)
|
|
|
@ -495,6 +472,26 @@ 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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
|
|
|
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
|
|
|
*
|
|
|
|
*
|
|
|
|