优化首页
This commit is contained in:
parent
0763a7e6a5
commit
20c50b1953
Binary file not shown.
|
After Width: | Height: | Size: 133 KiB |
|
|
@ -30,7 +30,7 @@
|
||||||
<div class="col-sm-7">
|
<div class="col-sm-7">
|
||||||
<div class="signin-info">
|
<div class="signin-info">
|
||||||
<div class="logopanel m-b">
|
<div class="logopanel m-b">
|
||||||
<h1><img alt="[ 云企互联 ]" src="../static/ruoyi.png" th:src="@{/ruoyi.png}"></h1>
|
<h1><img alt="[ 云企互联 ]" src="../static/juncong.png" th:src="@{/ruoyi.png}"></h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="m-b"></div>
|
<div class="m-b"></div>
|
||||||
<h4>欢迎使用 <strong>云企互联 后台管理系统</strong></h4>
|
<h4>欢迎使用 <strong>云企互联 后台管理系统</strong></h4>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.poi.hssf.usermodel.DVConstraint;
|
import org.apache.poi.hssf.usermodel.DVConstraint;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||||
|
|
@ -40,108 +41,94 @@ import com.ruoyi.common.config.Global;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Excel相关处理
|
* Excel相关处理
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
public class ExcelUtil<T>
|
public class ExcelUtil<T> {
|
||||||
{
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
private static final Logger log = LoggerFactory.getLogger(ExcelUtil.class);
|
||||||
|
|
||||||
public Class<T> clazz;
|
public Class<T> clazz;
|
||||||
|
|
||||||
public ExcelUtil(Class<T> clazz)
|
public ExcelUtil(Class<T> clazz) {
|
||||||
{
|
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对excel表单默认第一个索引名转换成list
|
* 对excel表单默认第一个索引名转换成list
|
||||||
*
|
*
|
||||||
* @param input 输入流
|
* @param input 输入流
|
||||||
* @return 转换后集合
|
* @return 转换后集合
|
||||||
*/
|
*/
|
||||||
public List<T> importExcel(InputStream input) throws Exception
|
public List<T> importExcel(InputStream input) throws Exception {
|
||||||
{
|
|
||||||
return importExcel(StringUtils.EMPTY, input);
|
return importExcel(StringUtils.EMPTY, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对excel表单指定表格索引名转换成list
|
* 对excel表单指定表格索引名转换成list
|
||||||
*
|
*
|
||||||
* @param sheetName 表格索引名
|
* @param sheetName 表格索引名
|
||||||
* @param input 输入流
|
* @param input 输入流
|
||||||
* @return 转换后集合
|
* @return 转换后集合
|
||||||
*/
|
*/
|
||||||
public List<T> importExcel(String sheetName, InputStream input) throws Exception
|
public List<T> importExcel(String sheetName, InputStream input) throws Exception {
|
||||||
{
|
|
||||||
List<T> list = new ArrayList<T>();
|
List<T> list = new ArrayList<T>();
|
||||||
|
|
||||||
Workbook workbook = WorkbookFactory.create(input);
|
Workbook workbook = WorkbookFactory.create(input);
|
||||||
Sheet sheet = null;
|
Sheet sheet = null;
|
||||||
if (StringUtils.isNotEmpty(sheetName))
|
if (StringUtils.isNotEmpty(sheetName)) {
|
||||||
{
|
|
||||||
// 如果指定sheet名,则取指定sheet中的内容.
|
// 如果指定sheet名,则取指定sheet中的内容.
|
||||||
sheet = workbook.getSheet(sheetName);
|
sheet = workbook.getSheet(sheetName);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// 如果传入的sheet名不存在则默认指向第1个sheet.
|
// 如果传入的sheet名不存在则默认指向第1个sheet.
|
||||||
sheet = workbook.getSheetAt(0);
|
sheet = workbook.getSheetAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sheet == null)
|
if (sheet == null) {
|
||||||
{
|
|
||||||
throw new IOException("文件sheet不存在");
|
throw new IOException("文件sheet不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
int rows = sheet.getPhysicalNumberOfRows();
|
int rows = sheet.getPhysicalNumberOfRows();
|
||||||
|
|
||||||
if (rows > 0)
|
if (rows > 0) {
|
||||||
{
|
|
||||||
// 默认序号
|
// 默认序号
|
||||||
int serialNum = 0;
|
int serialNum = 0;
|
||||||
// 有数据时才处理 得到类的所有field.
|
// 有数据时才处理 得到类的所有field.
|
||||||
Field[] allFields = clazz.getDeclaredFields();
|
Field[] allFields = clazz.getDeclaredFields();
|
||||||
// 定义一个map用于存放列的序号和field.
|
// 定义一个map用于存放列的序号和field.
|
||||||
Map<Integer, Field> fieldsMap = new HashMap<Integer, Field>();
|
Map<Integer, Field> fieldsMap = new HashMap<Integer, Field>();
|
||||||
for (int col = 0; col < allFields.length; col++)
|
for (int col = 0; col < allFields.length; col++) {
|
||||||
{
|
|
||||||
Field field = allFields[col];
|
Field field = allFields[col];
|
||||||
// 将有注解的field存放到map中.
|
// 将有注解的field存放到map中.
|
||||||
if (field.isAnnotationPresent(Excel.class))
|
if (field.isAnnotationPresent(Excel.class)) {
|
||||||
{
|
|
||||||
// 设置类的私有字段属性可访问.
|
// 设置类的私有字段属性可访问.
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Excel annotation = field.getAnnotation(Excel.class);
|
Excel annotation = field.getAnnotation(Excel.class);
|
||||||
fieldsMap.put(annotation.order(), field);
|
fieldsMap.put(annotation.order(), field);
|
||||||
if(annotation.order()>serialNum){
|
if (annotation.order() > serialNum) {
|
||||||
serialNum=annotation.order();
|
serialNum = annotation.order();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 2; i < rows; i++)
|
for (int i = 2; i < rows; i++) {
|
||||||
{
|
|
||||||
// 从第2行开始取数据,默认第一行是表头.
|
// 从第2行开始取数据,默认第一行是表头.
|
||||||
Row row = sheet.getRow(i);
|
Row row = sheet.getRow(i);
|
||||||
|
if (row == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int cellNum = serialNum;
|
int cellNum = serialNum;
|
||||||
T entity = null;
|
T entity = null;
|
||||||
for (int j = 0; j < serialNum; j++)
|
for (int j = 0; j < serialNum; j++) {
|
||||||
{
|
|
||||||
Cell cell = row.getCell(j);
|
Cell cell = row.getCell(j);
|
||||||
if (cell == null)
|
if (cell == null) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// 先设置Cell的类型,然后就可以把纯数字作为String类型读进来了
|
// 先设置Cell的类型,然后就可以把纯数字作为String类型读进来了
|
||||||
row.getCell(j).setCellType(CellType.STRING);
|
row.getCell(j).setCellType(CellType.STRING);
|
||||||
cell = row.getCell(j);
|
cell = row.getCell(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
String c = cell.getStringCellValue();
|
String c = cell.getStringCellValue();
|
||||||
if (StringUtils.isEmpty(c))
|
if (StringUtils.isEmpty(c)) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,62 +136,40 @@ public class ExcelUtil<T>
|
||||||
entity = (entity == null ? clazz.newInstance() : entity);
|
entity = (entity == null ? clazz.newInstance() : entity);
|
||||||
// 从map中得到对应列的field.
|
// 从map中得到对应列的field.
|
||||||
Field field = fieldsMap.get(j + 1);
|
Field field = fieldsMap.get(j + 1);
|
||||||
if(field==null){
|
if (field == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 取得类型,并根据对象类型设置值.
|
// 取得类型,并根据对象类型设置值.
|
||||||
Class<?> fieldType = field.getType();
|
Class<?> fieldType = field.getType();
|
||||||
if (String.class == fieldType)
|
if (String.class == fieldType) {
|
||||||
{
|
|
||||||
field.set(entity, String.valueOf(c));
|
field.set(entity, String.valueOf(c));
|
||||||
}
|
} else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType)) {
|
||||||
else if ((Integer.TYPE == fieldType) || (Integer.class == fieldType))
|
|
||||||
{
|
|
||||||
field.set(entity, Integer.parseInt(c));
|
field.set(entity, Integer.parseInt(c));
|
||||||
}
|
} else if ((Long.TYPE == fieldType) || (Long.class == fieldType)) {
|
||||||
else if ((Long.TYPE == fieldType) || (Long.class == fieldType))
|
|
||||||
{
|
|
||||||
field.set(entity, Long.valueOf(c));
|
field.set(entity, Long.valueOf(c));
|
||||||
}
|
} else if ((Float.TYPE == fieldType) || (Float.class == fieldType)) {
|
||||||
else if ((Float.TYPE == fieldType) || (Float.class == fieldType))
|
|
||||||
{
|
|
||||||
field.set(entity, Float.valueOf(c));
|
field.set(entity, Float.valueOf(c));
|
||||||
}
|
} else if ((Short.TYPE == fieldType) || (Short.class == fieldType)) {
|
||||||
else if ((Short.TYPE == fieldType) || (Short.class == fieldType))
|
|
||||||
{
|
|
||||||
field.set(entity, Short.valueOf(c));
|
field.set(entity, Short.valueOf(c));
|
||||||
}
|
} else if ((Double.TYPE == fieldType) || (Double.class == fieldType)) {
|
||||||
else if ((Double.TYPE == fieldType) || (Double.class == fieldType))
|
|
||||||
{
|
|
||||||
field.set(entity, Double.valueOf(c));
|
field.set(entity, Double.valueOf(c));
|
||||||
}
|
} else if (Character.TYPE == fieldType) {
|
||||||
else if (Character.TYPE == fieldType)
|
if ((c != null) && (c.length() > 0)) {
|
||||||
{
|
|
||||||
if ((c != null) && (c.length() > 0))
|
|
||||||
{
|
|
||||||
field.set(entity, Character.valueOf(c.charAt(0)));
|
field.set(entity, Character.valueOf(c.charAt(0)));
|
||||||
}
|
}
|
||||||
}
|
} else if (java.util.Date.class == fieldType) {
|
||||||
else if (java.util.Date.class == fieldType)
|
if (cell.getCellTypeEnum() == CellType.NUMERIC) {
|
||||||
{
|
|
||||||
if (cell.getCellTypeEnum() == CellType.NUMERIC)
|
|
||||||
{
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
cell.setCellValue(sdf.format(cell.getNumericCellValue()));
|
cell.setCellValue(sdf.format(cell.getNumericCellValue()));
|
||||||
c = sdf.format(cell.getNumericCellValue());
|
c = sdf.format(cell.getNumericCellValue());
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
c = cell.getStringCellValue();
|
c = cell.getStringCellValue();
|
||||||
}
|
}
|
||||||
}
|
} else if (java.math.BigDecimal.class == fieldType) {
|
||||||
else if (java.math.BigDecimal.class == fieldType)
|
|
||||||
{
|
|
||||||
c = cell.getStringCellValue();
|
c = cell.getStringCellValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (entity != null)
|
if (entity != null) {
|
||||||
{
|
|
||||||
list.add(entity);
|
list.add(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -215,25 +180,21 @@ public class ExcelUtil<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对list数据源将其里面的数据导入到excel表单
|
* 对list数据源将其里面的数据导入到excel表单
|
||||||
*
|
*
|
||||||
* @param list 导出数据集合
|
* @param list 导出数据集合
|
||||||
* @param sheetName 工作表的名称
|
* @param sheetName 工作表的名称
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public AjaxResult exportExcel(List<T> list, String sheetName)
|
public AjaxResult exportExcel(List<T> list, String sheetName) {
|
||||||
{
|
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
HSSFWorkbook workbook = null;
|
HSSFWorkbook workbook = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// 得到所有定义字段
|
// 得到所有定义字段
|
||||||
Field[] allFields = clazz.getDeclaredFields();
|
Field[] allFields = clazz.getDeclaredFields();
|
||||||
List<Field> fields = new ArrayList<Field>();
|
List<Field> fields = new ArrayList<Field>();
|
||||||
// 得到所有field并存放到一个list中.
|
// 得到所有field并存放到一个list中.
|
||||||
for (Field field : allFields)
|
for (Field field : allFields) {
|
||||||
{
|
if (field.isAnnotationPresent(Excel.class)) {
|
||||||
if (field.isAnnotationPresent(Excel.class))
|
|
||||||
{
|
|
||||||
fields.add(field);
|
fields.add(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -244,16 +205,12 @@ public class ExcelUtil<T>
|
||||||
int sheetSize = 65536;
|
int sheetSize = 65536;
|
||||||
// 取出一共有多少个sheet.
|
// 取出一共有多少个sheet.
|
||||||
double sheetNo = Math.ceil(list.size() / sheetSize);
|
double sheetNo = Math.ceil(list.size() / sheetSize);
|
||||||
for (int index = 0; index <= sheetNo; index++)
|
for (int index = 0; index <= sheetNo; index++) {
|
||||||
{
|
|
||||||
// 产生工作表对象
|
// 产生工作表对象
|
||||||
HSSFSheet sheet = workbook.createSheet();
|
HSSFSheet sheet = workbook.createSheet();
|
||||||
if (sheetNo == 0)
|
if (sheetNo == 0) {
|
||||||
{
|
|
||||||
workbook.setSheetName(index, sheetName);
|
workbook.setSheetName(index, sheetName);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// 设置工作表的名称.
|
// 设置工作表的名称.
|
||||||
workbook.setSheetName(index, sheetName + index);
|
workbook.setSheetName(index, sheetName + index);
|
||||||
}
|
}
|
||||||
|
|
@ -263,8 +220,7 @@ public class ExcelUtil<T>
|
||||||
// 产生一行
|
// 产生一行
|
||||||
row = sheet.createRow(0);
|
row = sheet.createRow(0);
|
||||||
// 写入各个字段的列头名称
|
// 写入各个字段的列头名称
|
||||||
for (int i = 0; i < fields.size(); i++)
|
for (int i = 0; i < fields.size(); i++) {
|
||||||
{
|
|
||||||
Field field = fields.get(i);
|
Field field = fields.get(i);
|
||||||
Excel attr = field.getAnnotation(Excel.class);
|
Excel attr = field.getAnnotation(Excel.class);
|
||||||
// 创建列
|
// 创建列
|
||||||
|
|
@ -274,16 +230,13 @@ public class ExcelUtil<T>
|
||||||
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
HSSFCellStyle cellStyle = workbook.createCellStyle();
|
||||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
if (attr.name().indexOf("注:") >= 0)
|
if (attr.name().indexOf("注:") >= 0) {
|
||||||
{
|
|
||||||
HSSFFont font = workbook.createFont();
|
HSSFFont font = workbook.createFont();
|
||||||
font.setColor(HSSFFont.COLOR_RED);
|
font.setColor(HSSFFont.COLOR_RED);
|
||||||
cellStyle.setFont(font);
|
cellStyle.setFont(font);
|
||||||
cellStyle.setFillForegroundColor(HSSFColorPredefined.YELLOW.getIndex());
|
cellStyle.setFillForegroundColor(HSSFColorPredefined.YELLOW.getIndex());
|
||||||
sheet.setColumnWidth(i, 6000);
|
sheet.setColumnWidth(i, 6000);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
HSSFFont font = workbook.createFont();
|
HSSFFont font = workbook.createFont();
|
||||||
// 粗体显示
|
// 粗体显示
|
||||||
font.setBold(true);
|
font.setBold(true);
|
||||||
|
|
@ -302,14 +255,12 @@ public class ExcelUtil<T>
|
||||||
cell.setCellValue(attr.name());
|
cell.setCellValue(attr.name());
|
||||||
|
|
||||||
// 如果设置了提示信息则鼠标放上去提示.
|
// 如果设置了提示信息则鼠标放上去提示.
|
||||||
if (StringUtils.isNotEmpty(attr.prompt()))
|
if (StringUtils.isNotEmpty(attr.prompt())) {
|
||||||
{
|
|
||||||
// 这里默认设了2-101列提示.
|
// 这里默认设了2-101列提示.
|
||||||
setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, i, i);
|
setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, i, i);
|
||||||
}
|
}
|
||||||
// 如果设置了combo属性则本列只能选择不能输入
|
// 如果设置了combo属性则本列只能选择不能输入
|
||||||
if (attr.combo().length > 0)
|
if (attr.combo().length > 0) {
|
||||||
{
|
|
||||||
// 这里默认设了2-101列只能选择不能输入.
|
// 这里默认设了2-101列只能选择不能输入.
|
||||||
setHSSFValidation(sheet, attr.combo(), 1, 100, i, i);
|
setHSSFValidation(sheet, attr.combo(), 1, 100, i, i);
|
||||||
}
|
}
|
||||||
|
|
@ -321,30 +272,25 @@ public class ExcelUtil<T>
|
||||||
HSSFCellStyle cs = workbook.createCellStyle();
|
HSSFCellStyle cs = workbook.createCellStyle();
|
||||||
cs.setAlignment(HorizontalAlignment.CENTER);
|
cs.setAlignment(HorizontalAlignment.CENTER);
|
||||||
cs.setVerticalAlignment(VerticalAlignment.CENTER);
|
cs.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
for (int i = startNo; i < endNo; i++)
|
for (int i = startNo; i < endNo; i++) {
|
||||||
{
|
|
||||||
row = sheet.createRow(i + 1 - startNo);
|
row = sheet.createRow(i + 1 - startNo);
|
||||||
// 得到导出对象.
|
// 得到导出对象.
|
||||||
T vo = (T) list.get(i);
|
T vo = (T) list.get(i);
|
||||||
for (int j = 0; j < fields.size(); j++)
|
for (int j = 0; j < fields.size(); j++) {
|
||||||
{
|
|
||||||
// 获得field.
|
// 获得field.
|
||||||
Field field = fields.get(j);
|
Field field = fields.get(j);
|
||||||
// 设置实体类私有属性可访问
|
// 设置实体类私有属性可访问
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Excel attr = field.getAnnotation(Excel.class);
|
Excel attr = field.getAnnotation(Excel.class);
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// 设置行高
|
// 设置行高
|
||||||
row.setHeight((short) (attr.height() * 20));
|
row.setHeight((short) (attr.height() * 20));
|
||||||
// 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
|
// 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
|
||||||
if (attr.isExport())
|
if (attr.isExport()) {
|
||||||
{
|
|
||||||
// 创建cell
|
// 创建cell
|
||||||
cell = row.createCell(j);
|
cell = row.createCell(j);
|
||||||
cell.setCellStyle(cs);
|
cell.setCellStyle(cs);
|
||||||
if (vo == null)
|
if (vo == null) {
|
||||||
{
|
|
||||||
// 如果数据存在就填入,不存在填入空格.
|
// 如果数据存在就填入,不存在填入空格.
|
||||||
cell.setCellValue("");
|
cell.setCellValue("");
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -352,24 +298,17 @@ public class ExcelUtil<T>
|
||||||
|
|
||||||
String dateFormat = attr.dateFormat();
|
String dateFormat = attr.dateFormat();
|
||||||
String readConverterExp = attr.readConverterExp();
|
String readConverterExp = attr.readConverterExp();
|
||||||
if (StringUtils.isNotEmpty(dateFormat))
|
if (StringUtils.isNotEmpty(dateFormat)) {
|
||||||
{
|
|
||||||
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) field.get(vo)));
|
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) field.get(vo)));
|
||||||
}
|
} else if (StringUtils.isNotEmpty(readConverterExp)) {
|
||||||
else if (StringUtils.isNotEmpty(readConverterExp))
|
|
||||||
{
|
|
||||||
cell.setCellValue(convertByExp(String.valueOf(field.get(vo)), readConverterExp));
|
cell.setCellValue(convertByExp(String.valueOf(field.get(vo)), readConverterExp));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
cell.setCellType(CellType.STRING);
|
cell.setCellType(CellType.STRING);
|
||||||
// 如果数据存在就填入,不存在填入空格.
|
// 如果数据存在就填入,不存在填入空格.
|
||||||
cell.setCellValue(StringUtils.isNull(field.get(vo)) ? attr.defaultValue() : field.get(vo) + attr.suffix());
|
cell.setCellValue(StringUtils.isNull(field.get(vo)) ? attr.defaultValue() : field.get(vo) + attr.suffix());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.error("导出Excel失败{}", e.getMessage());
|
log.error("导出Excel失败{}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -379,33 +318,21 @@ public class ExcelUtil<T>
|
||||||
out = new FileOutputStream(getAbsoluteFile(filename));
|
out = new FileOutputStream(getAbsoluteFile(filename));
|
||||||
workbook.write(out);
|
workbook.write(out);
|
||||||
return AjaxResult.success(filename);
|
return AjaxResult.success(filename);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.error("导出Excel异常{}", e.getMessage());
|
log.error("导出Excel异常{}", e.getMessage());
|
||||||
return AjaxResult.error("导出Excel失败,请联系网站管理员!");
|
return AjaxResult.error("导出Excel失败,请联系网站管理员!");
|
||||||
}
|
} finally {
|
||||||
finally
|
if (workbook != null) {
|
||||||
{
|
try {
|
||||||
if (workbook != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
workbook.close();
|
workbook.close();
|
||||||
}
|
} catch (IOException e1) {
|
||||||
catch (IOException e1)
|
|
||||||
{
|
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (out != null)
|
if (out != null) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
out.close();
|
out.close();
|
||||||
}
|
} catch (IOException e1) {
|
||||||
catch (IOException e1)
|
|
||||||
{
|
|
||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -414,19 +341,18 @@ public class ExcelUtil<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置单元格上提示
|
* 设置单元格上提示
|
||||||
*
|
*
|
||||||
* @param sheet 要设置的sheet.
|
* @param sheet 要设置的sheet.
|
||||||
* @param promptTitle 标题
|
* @param promptTitle 标题
|
||||||
* @param promptContent 内容
|
* @param promptContent 内容
|
||||||
* @param firstRow 开始行
|
* @param firstRow 开始行
|
||||||
* @param endRow 结束行
|
* @param endRow 结束行
|
||||||
* @param firstCol 开始列
|
* @param firstCol 开始列
|
||||||
* @param endCol 结束列
|
* @param endCol 结束列
|
||||||
* @return 设置好的sheet.
|
* @return 设置好的sheet.
|
||||||
*/
|
*/
|
||||||
public static HSSFSheet setHSSFPrompt(HSSFSheet sheet, String promptTitle, String promptContent, int firstRow,
|
public static HSSFSheet setHSSFPrompt(HSSFSheet sheet, String promptTitle, String promptContent, int firstRow,
|
||||||
int endRow, int firstCol, int endCol)
|
int endRow, int firstCol, int endCol) {
|
||||||
{
|
|
||||||
// 构造constraint对象
|
// 构造constraint对象
|
||||||
DVConstraint constraint = DVConstraint.createCustomFormulaConstraint("DD1");
|
DVConstraint constraint = DVConstraint.createCustomFormulaConstraint("DD1");
|
||||||
// 四个参数分别是:起始行、终止行、起始列、终止列
|
// 四个参数分别是:起始行、终止行、起始列、终止列
|
||||||
|
|
@ -440,18 +366,17 @@ public class ExcelUtil<T>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
||||||
*
|
*
|
||||||
* @param sheet 要设置的sheet.
|
* @param sheet 要设置的sheet.
|
||||||
* @param textlist 下拉框显示的内容
|
* @param textlist 下拉框显示的内容
|
||||||
* @param firstRow 开始行
|
* @param firstRow 开始行
|
||||||
* @param endRow 结束行
|
* @param endRow 结束行
|
||||||
* @param firstCol 开始列
|
* @param firstCol 开始列
|
||||||
* @param endCol 结束列
|
* @param endCol 结束列
|
||||||
* @return 设置好的sheet.
|
* @return 设置好的sheet.
|
||||||
*/
|
*/
|
||||||
public static HSSFSheet setHSSFValidation(HSSFSheet sheet, String[] textlist, int firstRow, int endRow,
|
public static HSSFSheet setHSSFValidation(HSSFSheet sheet, String[] textlist, int firstRow, int endRow,
|
||||||
int firstCol, int endCol)
|
int firstCol, int endCol) {
|
||||||
{
|
|
||||||
// 加载下拉列表内容
|
// 加载下拉列表内容
|
||||||
DVConstraint constraint = DVConstraint.createExplicitListConstraint(textlist);
|
DVConstraint constraint = DVConstraint.createExplicitListConstraint(textlist);
|
||||||
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
// 设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
|
||||||
|
|
@ -461,31 +386,25 @@ public class ExcelUtil<T>
|
||||||
sheet.addValidationData(dataValidationList);
|
sheet.addValidationData(dataValidationList);
|
||||||
return sheet;
|
return sheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析导出值 0=男,1=女,2=未知
|
* 解析导出值 0=男,1=女,2=未知
|
||||||
*
|
*
|
||||||
* @param propertyValue 参数值
|
* @param propertyValue 参数值
|
||||||
* @param converterExp 翻译注解
|
* @param converterExp 翻译注解
|
||||||
* @return 解析后值
|
* @return 解析后值
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static String convertByExp(String propertyValue, String converterExp) throws Exception
|
public static String convertByExp(String propertyValue, String converterExp) throws Exception {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
String[] convertSource = converterExp.split(",");
|
String[] convertSource = converterExp.split(",");
|
||||||
for (String item : convertSource)
|
for (String item : convertSource) {
|
||||||
{
|
|
||||||
String[] itemArray = item.split("=");
|
String[] itemArray = item.split("=");
|
||||||
if (itemArray[0].equals(propertyValue))
|
if (itemArray[0].equals(propertyValue)) {
|
||||||
{
|
|
||||||
return itemArray[1];
|
return itemArray[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return propertyValue;
|
return propertyValue;
|
||||||
|
|
@ -494,23 +413,20 @@ public class ExcelUtil<T>
|
||||||
/**
|
/**
|
||||||
* 编码文件名
|
* 编码文件名
|
||||||
*/
|
*/
|
||||||
public String encodingFilename(String filename)
|
public String encodingFilename(String filename) {
|
||||||
{
|
|
||||||
filename = UUID.randomUUID().toString() + "_" + filename + ".xls";
|
filename = UUID.randomUUID().toString() + "_" + filename + ".xls";
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取下载路径
|
* 获取下载路径
|
||||||
*
|
*
|
||||||
* @param filename 文件名称
|
* @param filename 文件名称
|
||||||
*/
|
*/
|
||||||
public String getAbsoluteFile(String filename)
|
public String getAbsoluteFile(String filename) {
|
||||||
{
|
|
||||||
String downloadPath = Global.getDownloadPath() + filename;
|
String downloadPath = Global.getDownloadPath() + filename;
|
||||||
File desc = new File(downloadPath);
|
File desc = new File(downloadPath);
|
||||||
if (!desc.getParentFile().exists())
|
if (!desc.getParentFile().exists()) {
|
||||||
{
|
|
||||||
desc.getParentFile().mkdirs();
|
desc.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
return downloadPath;
|
return downloadPath;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue