|
@@ -1,32 +1,5 @@
|
|
package com.ruoyi.common.utils.poi;
|
|
package com.ruoyi.common.utils.poi;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
-import java.io.OutputStream;
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.text.DecimalFormat;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Arrays;
|
|
|
|
-import java.util.Comparator;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Set;
|
|
|
|
-import java.util.UUID;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
-
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
-import org.apache.poi.ss.usermodel.*;
|
|
|
|
-import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
|
-import org.apache.poi.ss.util.CellReference;
|
|
|
|
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
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;
|
|
@@ -39,10 +12,24 @@ 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.StringUtils;
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
import com.ruoyi.common.utils.reflect.ReflectUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
|
+import org.apache.poi.ss.util.CellRangeAddressList;
|
|
|
|
+import org.apache.poi.ss.util.CellReference;
|
|
|
|
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.text.DecimalFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Excel相关处理
|
|
* Excel相关处理
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @author ruoyi
|
|
* @author ruoyi
|
|
*/
|
|
*/
|
|
public class ExcelUtil<T>
|
|
public class ExcelUtil<T>
|
|
@@ -124,7 +111,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 对excel表单默认第一个索引名转换成list
|
|
* 对excel表单默认第一个索引名转换成list
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param is 输入流
|
|
* @param is 输入流
|
|
* @return 转换后集合
|
|
* @return 转换后集合
|
|
*/
|
|
*/
|
|
@@ -135,7 +122,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 对excel表单指定表格索引名转换成list
|
|
* 对excel表单指定表格索引名转换成list
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param sheetName 表格索引名
|
|
* @param sheetName 表格索引名
|
|
* @param is 输入流
|
|
* @param is 输入流
|
|
* @return 转换后集合
|
|
* @return 转换后集合
|
|
@@ -291,7 +278,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param list 导出数据集合
|
|
* @param list 导出数据集合
|
|
* @param sheetName 工作表的名称
|
|
* @param sheetName 工作表的名称
|
|
* @return 结果
|
|
* @return 结果
|
|
@@ -436,7 +423,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param sheetName 工作表的名称
|
|
* @param sheetName 工作表的名称
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@@ -448,7 +435,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
* 对list数据源将其里面的数据导入到excel表单
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
public AjaxResult exportExcel()
|
|
public AjaxResult exportExcel()
|
|
@@ -781,7 +768,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 填充excel数据
|
|
* 填充excel数据
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param index 序号
|
|
* @param index 序号
|
|
* @param row 单元格行
|
|
* @param row 单元格行
|
|
*/
|
|
*/
|
|
@@ -808,7 +795,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 创建表格样式
|
|
* 创建表格样式
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param wb 工作薄对象
|
|
* @param wb 工作薄对象
|
|
* @return 样式列表
|
|
* @return 样式列表
|
|
*/
|
|
*/
|
|
@@ -846,13 +833,15 @@ public class ExcelUtil<T>
|
|
headerFont.setColor(IndexedColors.WHITE.getIndex());
|
|
headerFont.setColor(IndexedColors.WHITE.getIndex());
|
|
style.setFont(headerFont);
|
|
style.setFont(headerFont);
|
|
styles.put("header", style);
|
|
styles.put("header", style);
|
|
-
|
|
|
|
|
|
+
|
|
style = wb.createCellStyle();
|
|
style = wb.createCellStyle();
|
|
|
|
+ style.cloneStyleFrom(styles.get("data"));
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
style.setAlignment(HorizontalAlignment.CENTER);
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
Font totalFont = wb.createFont();
|
|
Font totalFont = wb.createFont();
|
|
totalFont.setFontName("Arial");
|
|
totalFont.setFontName("Arial");
|
|
totalFont.setFontHeightInPoints((short) 10);
|
|
totalFont.setFontHeightInPoints((short) 10);
|
|
|
|
+ totalFont.setBold(true);
|
|
style.setFont(totalFont);
|
|
style.setFont(totalFont);
|
|
styles.put("total", style);
|
|
styles.put("total", style);
|
|
|
|
|
|
@@ -890,7 +879,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 设置单元格信息
|
|
* 设置单元格信息
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param value 单元格值
|
|
* @param value 单元格值
|
|
* @param attr 注解相关
|
|
* @param attr 注解相关
|
|
* @param cell 单元格信息
|
|
* @param cell 单元格信息
|
|
@@ -997,7 +986,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 设置 POI XSSFSheet 单元格提示
|
|
* 设置 POI XSSFSheet 单元格提示
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param sheet 表单
|
|
* @param sheet 表单
|
|
* @param promptTitle 提示标题
|
|
* @param promptTitle 提示标题
|
|
* @param promptContent 提示内容
|
|
* @param promptContent 提示内容
|
|
@@ -1020,7 +1009,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
|
* 设置某些列的值只能输入预制的数据,显示下拉框.
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param sheet 要设置的sheet.
|
|
* @param sheet 要设置的sheet.
|
|
* @param textlist 下拉框显示的内容
|
|
* @param textlist 下拉框显示的内容
|
|
* @param firstRow 开始行
|
|
* @param firstRow 开始行
|
|
@@ -1054,7 +1043,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 解析导出值 0=男,1=女,2=未知
|
|
* 解析导出值 0=男,1=女,2=未知
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param propertyValue 参数值
|
|
* @param propertyValue 参数值
|
|
* @param converterExp 翻译注解
|
|
* @param converterExp 翻译注解
|
|
* @param separator 分隔符
|
|
* @param separator 分隔符
|
|
@@ -1091,7 +1080,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 反向解析值 男=0,女=1,未知=2
|
|
* 反向解析值 男=0,女=1,未知=2
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param propertyValue 参数值
|
|
* @param propertyValue 参数值
|
|
* @param converterExp 翻译注解
|
|
* @param converterExp 翻译注解
|
|
* @param separator 分隔符
|
|
* @param separator 分隔符
|
|
@@ -1128,7 +1117,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 解析字典值
|
|
* 解析字典值
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param dictValue 字典值
|
|
* @param dictValue 字典值
|
|
* @param dictType 字典类型
|
|
* @param dictType 字典类型
|
|
* @param separator 分隔符
|
|
* @param separator 分隔符
|
|
@@ -1141,7 +1130,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 反向解析值字典值
|
|
* 反向解析值字典值
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param dictLabel 字典标签
|
|
* @param dictLabel 字典标签
|
|
* @param dictType 字典类型
|
|
* @param dictType 字典类型
|
|
* @param separator 分隔符
|
|
* @param separator 分隔符
|
|
@@ -1166,7 +1155,10 @@ public class ExcelUtil<T>
|
|
}
|
|
}
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- temp = Double.valueOf(text);
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(text))
|
|
|
|
+ {
|
|
|
|
+ temp = Double.valueOf(text);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
catch (NumberFormatException e)
|
|
catch (NumberFormatException e)
|
|
{
|
|
{
|
|
@@ -1185,16 +1177,24 @@ public class ExcelUtil<T>
|
|
Cell cell = null;
|
|
Cell cell = null;
|
|
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
Row row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
Set<Integer> keys = statistics.keySet();
|
|
Set<Integer> keys = statistics.keySet();
|
|
- cell = row.createCell(0);
|
|
|
|
- cell.setCellStyle(styles.get("total"));
|
|
|
|
- cell.setCellValue("合计");
|
|
|
|
|
|
|
|
- for (Integer key : keys)
|
|
|
|
|
|
+ for (int i = 0; i < sheet.getRow(0).getLastCellNum(); i ++)
|
|
{
|
|
{
|
|
- cell = row.createCell(key);
|
|
|
|
|
|
+ cell = row.createCell(i);
|
|
cell.setCellStyle(styles.get("total"));
|
|
cell.setCellStyle(styles.get("total"));
|
|
- cell.setCellValue(DOUBLE_FORMAT.format(statistics.get(key)));
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ int temp = 16384;
|
|
|
|
+ for (Integer key : keys)
|
|
|
|
+ {
|
|
|
|
+ if (temp > key)
|
|
|
|
+ {
|
|
|
|
+ temp = key;
|
|
|
|
+ }
|
|
|
|
+ row.getCell(key).setCellValue(DOUBLE_FORMAT.format(statistics.get(key)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ row.getCell(temp - 1).setCellValue("合计");
|
|
statistics.clear();
|
|
statistics.clear();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1211,7 +1211,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取下载路径
|
|
* 获取下载路径
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param filename 文件名称
|
|
* @param filename 文件名称
|
|
*/
|
|
*/
|
|
public String getAbsoluteFile(String filename)
|
|
public String getAbsoluteFile(String filename)
|
|
@@ -1227,7 +1227,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取bean中的属性值
|
|
* 获取bean中的属性值
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param vo 实体对象
|
|
* @param vo 实体对象
|
|
* @param field 字段
|
|
* @param field 字段
|
|
* @param excel 注解
|
|
* @param excel 注解
|
|
@@ -1258,7 +1258,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 以类的属性的get方法方法形式获取值
|
|
* 以类的属性的get方法方法形式获取值
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param o
|
|
* @param o
|
|
* @param name
|
|
* @param name
|
|
* @return value
|
|
* @return value
|
|
@@ -1328,7 +1328,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 创建工作表
|
|
* 创建工作表
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param sheetNo sheet数量
|
|
* @param sheetNo sheet数量
|
|
* @param index 序号
|
|
* @param index 序号
|
|
*/
|
|
*/
|
|
@@ -1349,7 +1349,7 @@ public class ExcelUtil<T>
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取单元格值
|
|
* 获取单元格值
|
|
- *
|
|
|
|
|
|
+ *
|
|
* @param row 获取的行
|
|
* @param row 获取的行
|
|
* @param column 获取单元格列号
|
|
* @param column 获取单元格列号
|
|
* @return 单元格值
|
|
* @return 单元格值
|
|
@@ -1406,4 +1406,4 @@ public class ExcelUtil<T>
|
|
}
|
|
}
|
|
return val;
|
|
return val;
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|