|
|
|
@ -55,6 +55,7 @@ import com.ruoyi.common.core.annotation.Excel;
|
|
|
|
|
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
|
|
|
|
import com.ruoyi.common.core.annotation.Excel.Type;
|
|
|
|
|
import com.ruoyi.common.core.annotation.Excels;
|
|
|
|
|
import com.ruoyi.common.core.exception.UtilException;
|
|
|
|
|
import com.ruoyi.common.core.text.Convert;
|
|
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
|
|
@ -260,9 +261,23 @@ public class ExcelUtil<T>
|
|
|
|
|
* @param is 输入流
|
|
|
|
|
* @return 转换后集合
|
|
|
|
|
*/
|
|
|
|
|
public List<T> importExcel(InputStream is) throws Exception
|
|
|
|
|
public List<T> importExcel(InputStream is)
|
|
|
|
|
{
|
|
|
|
|
return importExcel(is, 0);
|
|
|
|
|
List<T> list = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
list = importExcel(is, 0);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.error("导入Excel异常{}", e.getMessage());
|
|
|
|
|
throw new UtilException(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
IOUtils.closeQuietly(is);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -299,7 +314,6 @@ public class ExcelUtil<T>
|
|
|
|
|
|
|
|
|
|
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
|
|
|
|
|
int rows = sheet.getLastRowNum();
|
|
|
|
|
|
|
|
|
|
if (rows > 0)
|
|
|
|
|
{
|
|
|
|
|
// 定义一个map用于存放excel列的序号和field.
|
|
|
|
@ -414,13 +428,13 @@ public class ExcelUtil<T>
|
|
|
|
|
{
|
|
|
|
|
propertyName = field.getName() + "." + attr.targetAttr();
|
|
|
|
|
}
|
|
|
|
|
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
|
|
|
|
if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
|
|
|
|
{
|
|
|
|
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
|
|
|
|
}
|
|
|
|
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
|
|
|
|
{
|
|
|
|
|
val = dataFormatHandlerAdapter(val, attr);
|
|
|
|
|
val = dataFormatHandlerAdapter(val, attr, null);
|
|
|
|
|
}
|
|
|
|
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
|
|
|
|
}
|
|
|
|
@ -910,7 +924,7 @@ public class ExcelUtil<T>
|
|
|
|
|
}
|
|
|
|
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
|
|
|
|
{
|
|
|
|
|
cell.setCellValue(dataFormatHandlerAdapter(value, attr));
|
|
|
|
|
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
@ -1097,13 +1111,13 @@ public class ExcelUtil<T>
|
|
|
|
|
* @param excel 数据注解
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String dataFormatHandlerAdapter(Object value, Excel excel)
|
|
|
|
|
public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Object instance = excel.handler().newInstance();
|
|
|
|
|
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
|
|
|
|
|
value = formatMethod.invoke(instance, value, excel.args());
|
|
|
|
|
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class });
|
|
|
|
|
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|