|
@@ -1,8 +1,6 @@
|
|
package com.ruoyi.common.utils.poi;
|
|
package com.ruoyi.common.utils.poi;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
import cn.hutool.core.convert.Convert;
|
|
-import cn.hutool.core.lang.Validator;
|
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
|
import com.ruoyi.common.annotation.Excel;
|
|
import com.ruoyi.common.annotation.Excel;
|
|
import com.ruoyi.common.annotation.Excel.ColumnType;
|
|
import com.ruoyi.common.annotation.Excel.ColumnType;
|
|
import com.ruoyi.common.annotation.Excel.Type;
|
|
import com.ruoyi.common.annotation.Excel.Type;
|
|
@@ -12,6 +10,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
|
import com.ruoyi.common.exception.CustomException;
|
|
import com.ruoyi.common.exception.CustomException;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
import com.ruoyi.common.utils.DictUtils;
|
|
import com.ruoyi.common.utils.DictUtils;
|
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.file.FileTypeUtils;
|
|
import com.ruoyi.common.utils.file.FileTypeUtils;
|
|
import com.ruoyi.common.utils.file.ImageUtils;
|
|
import com.ruoyi.common.utils.file.ImageUtils;
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
@@ -125,7 +124,7 @@ public class ExcelUtil<T>
|
|
*/
|
|
*/
|
|
public List<T> importExcel(InputStream is) throws Exception
|
|
public List<T> importExcel(InputStream is) throws Exception
|
|
{
|
|
{
|
|
- return importExcel(StrUtil.EMPTY, is);
|
|
|
|
|
|
+ return importExcel(StringUtils.EMPTY, is);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -141,7 +140,7 @@ public class ExcelUtil<T>
|
|
this.wb = WorkbookFactory.create(is);
|
|
this.wb = WorkbookFactory.create(is);
|
|
List<T> list = new ArrayList<T>();
|
|
List<T> list = new ArrayList<T>();
|
|
Sheet sheet = null;
|
|
Sheet sheet = null;
|
|
- if (Validator.isNotEmpty(sheetName))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(sheetName))
|
|
{
|
|
{
|
|
// 如果指定sheet名,则取指定sheet中的内容.
|
|
// 如果指定sheet名,则取指定sheet中的内容.
|
|
sheet = wb.getSheet(sheetName);
|
|
sheet = wb.getSheet(sheetName);
|
|
@@ -168,7 +167,7 @@ public class ExcelUtil<T>
|
|
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
|
|
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
|
|
{
|
|
{
|
|
Cell cell = heard.getCell(i);
|
|
Cell cell = heard.getCell(i);
|
|
- if (Validator.isNotNull(cell))
|
|
|
|
|
|
+ if (StringUtils.isNotNull(cell))
|
|
{
|
|
{
|
|
String value = this.getCellValue(heard, i).toString();
|
|
String value = this.getCellValue(heard, i).toString();
|
|
cellMap.put(value, i);
|
|
cellMap.put(value, i);
|
|
@@ -219,14 +218,14 @@ public class ExcelUtil<T>
|
|
if (String.class == fieldType)
|
|
if (String.class == fieldType)
|
|
{
|
|
{
|
|
String s = Convert.toStr(val);
|
|
String s = Convert.toStr(val);
|
|
- if (StrUtil.endWith(s, ".0"))
|
|
|
|
|
|
+ if (StringUtils.endWith(s, ".0"))
|
|
{
|
|
{
|
|
- val = StrUtil.subBefore(s, ".0",false);
|
|
|
|
|
|
+ val = StringUtils.subBefore(s, ".0",false);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
|
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
|
- if (Validator.isNotEmpty(dateFormat))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(dateFormat))
|
|
{
|
|
{
|
|
val = DateUtils.parseDateToStr(dateFormat, (Date) val);
|
|
val = DateUtils.parseDateToStr(dateFormat, (Date) val);
|
|
}
|
|
}
|
|
@@ -236,7 +235,7 @@ public class ExcelUtil<T>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && Validator.isNumber(Convert.toStr(val)))
|
|
|
|
|
|
+ else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
|
|
{
|
|
{
|
|
val = Convert.toInt(val);
|
|
val = Convert.toInt(val);
|
|
}
|
|
}
|
|
@@ -271,19 +270,19 @@ public class ExcelUtil<T>
|
|
{
|
|
{
|
|
val = Convert.toBool(val, false);
|
|
val = Convert.toBool(val, false);
|
|
}
|
|
}
|
|
- if (Validator.isNotNull(fieldType))
|
|
|
|
|
|
+ if (StringUtils.isNotNull(fieldType))
|
|
{
|
|
{
|
|
Excel attr = field.getAnnotation(Excel.class);
|
|
Excel attr = field.getAnnotation(Excel.class);
|
|
String propertyName = field.getName();
|
|
String propertyName = field.getName();
|
|
- if (Validator.isNotEmpty(attr.targetAttr()))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(attr.targetAttr()))
|
|
{
|
|
{
|
|
propertyName = field.getName() + "." + attr.targetAttr();
|
|
propertyName = field.getName() + "." + attr.targetAttr();
|
|
}
|
|
}
|
|
- else if (Validator.isNotEmpty(attr.readConverterExp()))
|
|
|
|
|
|
+ else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
|
{
|
|
{
|
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
|
}
|
|
}
|
|
- else if (Validator.isNotEmpty(attr.dictType()))
|
|
|
|
|
|
+ else if (StringUtils.isNotEmpty(attr.dictType()))
|
|
{
|
|
{
|
|
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
|
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
|
}
|
|
}
|
|
@@ -509,13 +508,13 @@ public class ExcelUtil<T>
|
|
{
|
|
{
|
|
if (ColumnType.STRING == attr.cellType())
|
|
if (ColumnType.STRING == attr.cellType())
|
|
{
|
|
{
|
|
- cell.setCellValue(Validator.isNull(value) ? attr.defaultValue() : value + attr.suffix());
|
|
|
|
|
|
+ cell.setCellValue(StringUtils.isNull(value) ? attr.defaultValue() : value + attr.suffix());
|
|
}
|
|
}
|
|
else if (ColumnType.NUMERIC == attr.cellType())
|
|
else if (ColumnType.NUMERIC == attr.cellType())
|
|
{
|
|
{
|
|
- if (Validator.isNotNull(value))
|
|
|
|
|
|
+ if (StringUtils.isNotNull(value))
|
|
{
|
|
{
|
|
- cell.setCellValue(StrUtil.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
|
|
|
|
|
|
+ cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (ColumnType.IMAGE == attr.cellType())
|
|
else if (ColumnType.IMAGE == attr.cellType())
|
|
@@ -523,7 +522,7 @@ public class ExcelUtil<T>
|
|
ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
|
|
ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
|
|
cell.getRow().getRowNum() + 1);
|
|
cell.getRow().getRowNum() + 1);
|
|
String imagePath = Convert.toStr(value);
|
|
String imagePath = Convert.toStr(value);
|
|
- if (Validator.isNotEmpty(imagePath))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(imagePath))
|
|
{
|
|
{
|
|
byte[] data = ImageUtils.getImage(imagePath);
|
|
byte[] data = ImageUtils.getImage(imagePath);
|
|
getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
|
|
getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
|
|
@@ -576,7 +575,7 @@ public class ExcelUtil<T>
|
|
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
|
sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
|
}
|
|
}
|
|
// 如果设置了提示信息则鼠标放上去提示.
|
|
// 如果设置了提示信息则鼠标放上去提示.
|
|
- if (Validator.isNotEmpty(attr.prompt()))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(attr.prompt()))
|
|
{
|
|
{
|
|
// 这里默认设了2-101列提示.
|
|
// 这里默认设了2-101列提示.
|
|
setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
|
|
setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
|
|
@@ -613,15 +612,15 @@ public class ExcelUtil<T>
|
|
String readConverterExp = attr.readConverterExp();
|
|
String readConverterExp = attr.readConverterExp();
|
|
String separator = attr.separator();
|
|
String separator = attr.separator();
|
|
String dictType = attr.dictType();
|
|
String dictType = attr.dictType();
|
|
- if (Validator.isNotEmpty(dateFormat) && Validator.isNotNull(value))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
|
{
|
|
{
|
|
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
|
cell.setCellValue(DateUtils.parseDateToStr(dateFormat, (Date) value));
|
|
}
|
|
}
|
|
- else if (Validator.isNotEmpty(readConverterExp) && Validator.isNotNull(value))
|
|
|
|
|
|
+ else if (StringUtils.isNotEmpty(readConverterExp) && StringUtils.isNotNull(value))
|
|
{
|
|
{
|
|
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
|
|
cell.setCellValue(convertByExp(Convert.toStr(value), readConverterExp, separator));
|
|
}
|
|
}
|
|
- else if (Validator.isNotEmpty(dictType) && Validator.isNotNull(value))
|
|
|
|
|
|
+ else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value))
|
|
{
|
|
{
|
|
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
|
|
cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator));
|
|
}
|
|
}
|
|
@@ -716,7 +715,7 @@ public class ExcelUtil<T>
|
|
for (String item : convertSource)
|
|
for (String item : convertSource)
|
|
{
|
|
{
|
|
String[] itemArray = item.split("=");
|
|
String[] itemArray = item.split("=");
|
|
- if (StrUtil.containsAny(propertyValue, separator))
|
|
|
|
|
|
+ if (StringUtils.containsAny(propertyValue, separator))
|
|
{
|
|
{
|
|
for (String value : propertyValue.split(separator))
|
|
for (String value : propertyValue.split(separator))
|
|
{
|
|
{
|
|
@@ -735,7 +734,7 @@ public class ExcelUtil<T>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return StrUtil.strip(propertyString.toString(), null,separator);
|
|
|
|
|
|
+ return StringUtils.strip(propertyString.toString(), null,separator);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -753,7 +752,7 @@ public class ExcelUtil<T>
|
|
for (String item : convertSource)
|
|
for (String item : convertSource)
|
|
{
|
|
{
|
|
String[] itemArray = item.split("=");
|
|
String[] itemArray = item.split("=");
|
|
- if (StrUtil.containsAny(propertyValue, separator))
|
|
|
|
|
|
+ if (StringUtils.containsAny(propertyValue, separator))
|
|
{
|
|
{
|
|
for (String value : propertyValue.split(separator))
|
|
for (String value : propertyValue.split(separator))
|
|
{
|
|
{
|
|
@@ -772,7 +771,7 @@ public class ExcelUtil<T>
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return StrUtil.strip(propertyString.toString(), null,separator);
|
|
|
|
|
|
+ return StringUtils.strip(propertyString.toString(), null,separator);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -885,7 +884,7 @@ public class ExcelUtil<T>
|
|
private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
|
|
private Object getTargetValue(T vo, Field field, Excel excel) throws Exception
|
|
{
|
|
{
|
|
Object o = field.get(vo);
|
|
Object o = field.get(vo);
|
|
- if (Validator.isNotEmpty(excel.targetAttr()))
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(excel.targetAttr()))
|
|
{
|
|
{
|
|
String target = excel.targetAttr();
|
|
String target = excel.targetAttr();
|
|
if (target.contains("."))
|
|
if (target.contains("."))
|
|
@@ -914,7 +913,7 @@ public class ExcelUtil<T>
|
|
*/
|
|
*/
|
|
private Object getValue(Object o, String name) throws Exception
|
|
private Object getValue(Object o, String name) throws Exception
|
|
{
|
|
{
|
|
- if (Validator.isNotNull(o) && Validator.isNotEmpty(name))
|
|
|
|
|
|
+ if (StringUtils.isNotNull(o) && StringUtils.isNotEmpty(name))
|
|
{
|
|
{
|
|
Class<?> clazz = o.getClass();
|
|
Class<?> clazz = o.getClass();
|
|
Field field = clazz.getDeclaredField(name);
|
|
Field field = clazz.getDeclaredField(name);
|
|
@@ -1027,7 +1026,7 @@ public class ExcelUtil<T>
|
|
try
|
|
try
|
|
{
|
|
{
|
|
Cell cell = row.getCell(column);
|
|
Cell cell = row.getCell(column);
|
|
- if (Validator.isNotNull(cell))
|
|
|
|
|
|
+ if (StringUtils.isNotNull(cell))
|
|
{
|
|
{
|
|
if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA)
|
|
if (cell.getCellType() == CellType.NUMERIC || cell.getCellType() == CellType.FORMULA)
|
|
{
|
|
{
|