提交者
Gitee
!686 导出Excel,提高导出效率
Merge pull request !686 from wzy1024/wzy1024
正在显示
1 个修改的文件
包含
37 行增加
和
70 行删除
| 1 | package com.ruoyi.common.utils.poi; | 1 | package com.ruoyi.common.utils.poi; |
| 2 | 2 | ||
| 3 | -import java.io.File; | ||
| 4 | -import java.io.FileOutputStream; | ||
| 5 | -import java.io.IOException; | ||
| 6 | -import java.io.InputStream; | ||
| 7 | -import java.io.OutputStream; | ||
| 8 | -import java.lang.reflect.Field; | ||
| 9 | -import java.lang.reflect.Method; | ||
| 10 | -import java.lang.reflect.ParameterizedType; | ||
| 11 | -import java.math.BigDecimal; | ||
| 12 | -import java.text.DecimalFormat; | ||
| 13 | -import java.time.LocalDate; | ||
| 14 | -import java.time.LocalDateTime; | ||
| 15 | -import java.util.ArrayList; | ||
| 16 | -import java.util.Arrays; | ||
| 17 | -import java.util.Collection; | ||
| 18 | -import java.util.Comparator; | ||
| 19 | -import java.util.Date; | ||
| 20 | -import java.util.HashMap; | ||
| 21 | -import java.util.List; | ||
| 22 | -import java.util.Map; | ||
| 23 | -import java.util.Set; | ||
| 24 | -import java.util.UUID; | ||
| 25 | -import java.util.stream.Collectors; | ||
| 26 | -import javax.servlet.http.HttpServletResponse; | ||
| 27 | -import org.apache.commons.lang3.ArrayUtils; | ||
| 28 | -import org.apache.commons.lang3.RegExUtils; | ||
| 29 | -import org.apache.commons.lang3.reflect.FieldUtils; | ||
| 30 | -import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | ||
| 31 | -import org.apache.poi.hssf.usermodel.HSSFPicture; | ||
| 32 | -import org.apache.poi.hssf.usermodel.HSSFPictureData; | ||
| 33 | -import org.apache.poi.hssf.usermodel.HSSFShape; | ||
| 34 | -import org.apache.poi.hssf.usermodel.HSSFSheet; | ||
| 35 | -import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||
| 36 | -import org.apache.poi.ooxml.POIXMLDocumentPart; | ||
| 37 | -import org.apache.poi.ss.usermodel.BorderStyle; | ||
| 38 | -import org.apache.poi.ss.usermodel.Cell; | ||
| 39 | -import org.apache.poi.ss.usermodel.CellStyle; | ||
| 40 | -import org.apache.poi.ss.usermodel.CellType; | ||
| 41 | -import org.apache.poi.ss.usermodel.ClientAnchor; | ||
| 42 | -import org.apache.poi.ss.usermodel.DataValidation; | ||
| 43 | -import org.apache.poi.ss.usermodel.DataValidationConstraint; | ||
| 44 | -import org.apache.poi.ss.usermodel.DataValidationHelper; | ||
| 45 | -import org.apache.poi.ss.usermodel.DateUtil; | ||
| 46 | -import org.apache.poi.ss.usermodel.Drawing; | ||
| 47 | -import org.apache.poi.ss.usermodel.FillPatternType; | ||
| 48 | -import org.apache.poi.ss.usermodel.Font; | ||
| 49 | -import org.apache.poi.ss.usermodel.HorizontalAlignment; | ||
| 50 | -import org.apache.poi.ss.usermodel.IndexedColors; | ||
| 51 | -import org.apache.poi.ss.usermodel.Name; | ||
| 52 | -import org.apache.poi.ss.usermodel.PictureData; | ||
| 53 | -import org.apache.poi.ss.usermodel.Row; | ||
| 54 | -import org.apache.poi.ss.usermodel.Sheet; | ||
| 55 | -import org.apache.poi.ss.usermodel.VerticalAlignment; | ||
| 56 | -import org.apache.poi.ss.usermodel.Workbook; | ||
| 57 | -import org.apache.poi.ss.usermodel.WorkbookFactory; | ||
| 58 | -import org.apache.poi.ss.util.CellRangeAddress; | ||
| 59 | -import org.apache.poi.ss.util.CellRangeAddressList; | ||
| 60 | -import org.apache.poi.util.IOUtils; | ||
| 61 | -import org.apache.poi.xssf.streaming.SXSSFWorkbook; | ||
| 62 | -import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | ||
| 63 | -import org.apache.poi.xssf.usermodel.XSSFDataValidation; | ||
| 64 | -import org.apache.poi.xssf.usermodel.XSSFDrawing; | ||
| 65 | -import org.apache.poi.xssf.usermodel.XSSFPicture; | ||
| 66 | -import org.apache.poi.xssf.usermodel.XSSFShape; | ||
| 67 | -import org.apache.poi.xssf.usermodel.XSSFSheet; | ||
| 68 | -import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||
| 69 | -import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; | ||
| 70 | -import org.slf4j.Logger; | ||
| 71 | -import org.slf4j.LoggerFactory; | ||
| 72 | import com.ruoyi.common.annotation.Excel; | 3 | import com.ruoyi.common.annotation.Excel; |
| 73 | import com.ruoyi.common.annotation.Excel.ColumnType; | 4 | import com.ruoyi.common.annotation.Excel.ColumnType; |
| 74 | import com.ruoyi.common.annotation.Excel.Type; | 5 | import com.ruoyi.common.annotation.Excel.Type; |
| @@ -84,6 +15,32 @@ import com.ruoyi.common.utils.file.FileTypeUtils; | @@ -84,6 +15,32 @@ import com.ruoyi.common.utils.file.FileTypeUtils; | ||
| 84 | import com.ruoyi.common.utils.file.FileUtils; | 15 | import com.ruoyi.common.utils.file.FileUtils; |
| 85 | import com.ruoyi.common.utils.file.ImageUtils; | 16 | import com.ruoyi.common.utils.file.ImageUtils; |
| 86 | import com.ruoyi.common.utils.reflect.ReflectUtils; | 17 | import com.ruoyi.common.utils.reflect.ReflectUtils; |
| 18 | +import org.apache.commons.lang3.ArrayUtils; | ||
| 19 | +import org.apache.commons.lang3.RegExUtils; | ||
| 20 | +import org.apache.commons.lang3.reflect.FieldUtils; | ||
| 21 | +import org.apache.poi.hssf.usermodel.*; | ||
| 22 | +import org.apache.poi.ooxml.POIXMLDocumentPart; | ||
| 23 | +import org.apache.poi.ss.usermodel.*; | ||
| 24 | +import org.apache.poi.ss.util.CellRangeAddress; | ||
| 25 | +import org.apache.poi.ss.util.CellRangeAddressList; | ||
| 26 | +import org.apache.poi.util.IOUtils; | ||
| 27 | +import org.apache.poi.xssf.streaming.SXSSFWorkbook; | ||
| 28 | +import org.apache.poi.xssf.usermodel.*; | ||
| 29 | +import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; | ||
| 30 | +import org.slf4j.Logger; | ||
| 31 | +import org.slf4j.LoggerFactory; | ||
| 32 | + | ||
| 33 | +import javax.servlet.http.HttpServletResponse; | ||
| 34 | +import java.io.*; | ||
| 35 | +import java.lang.reflect.Field; | ||
| 36 | +import java.lang.reflect.Method; | ||
| 37 | +import java.lang.reflect.ParameterizedType; | ||
| 38 | +import java.math.BigDecimal; | ||
| 39 | +import java.text.DecimalFormat; | ||
| 40 | +import java.time.LocalDate; | ||
| 41 | +import java.time.LocalDateTime; | ||
| 42 | +import java.util.*; | ||
| 43 | +import java.util.stream.Collectors; | ||
| 87 | 44 | ||
| 88 | /** | 45 | /** |
| 89 | * Excel相关处理 | 46 | * Excel相关处理 |
| @@ -99,6 +56,12 @@ public class ExcelUtil<T> | @@ -99,6 +56,12 @@ public class ExcelUtil<T> | ||
| 99 | public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; | 56 | public static final String[] FORMULA_STR = { "=", "-", "+", "@" }; |
| 100 | 57 | ||
| 101 | /** | 58 | /** |
| 59 | + * 导出Excel时,如果有大量的字典数据,就会有大量的查询redis(打开、关闭),导致特别慢。 | ||
| 60 | + * 于是使用map存储字典数据,相同的key就不需要再次去查询redis | ||
| 61 | + */ | ||
| 62 | + public Map<String,String> sysDictMap = new HashMap<String,String>(); | ||
| 63 | + | ||
| 64 | + /** | ||
| 102 | * Excel sheet最大行数,默认65536 | 65 | * Excel sheet最大行数,默认65536 |
| 103 | */ | 66 | */ |
| 104 | public static final int sheetSize = 65536; | 67 | public static final int sheetSize = 65536; |
| @@ -1034,7 +997,11 @@ public class ExcelUtil<T> | @@ -1034,7 +997,11 @@ public class ExcelUtil<T> | ||
| 1034 | } | 997 | } |
| 1035 | else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) | 998 | else if (StringUtils.isNotEmpty(dictType) && StringUtils.isNotNull(value)) |
| 1036 | { | 999 | { |
| 1037 | - cell.setCellValue(convertDictByExp(Convert.toStr(value), dictType, separator)); | 1000 | + if (!sysDictMap.containsKey(dictType+value)){ |
| 1001 | + String lable = convertDictByExp(Convert.toStr(value), dictType, separator); | ||
| 1002 | + sysDictMap.put(dictType+value,lable); | ||
| 1003 | + } | ||
| 1004 | + cell.setCellValue(sysDictMap.get(dictType+value)); | ||
| 1038 | } | 1005 | } |
| 1039 | else if (value instanceof BigDecimal && -1 != attr.scale()) | 1006 | else if (value instanceof BigDecimal && -1 != attr.scale()) |
| 1040 | { | 1007 | { |
-
请 注册 或 登录 后发表评论