From c404c280f726af9518afe1dcd8ab61d5fc3c1a4f Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 10 Jul 2020 15:12:20 +0800 Subject: [PATCH] =?UTF-8?q?Excel=E6=94=AF=E6=8C=81sort=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/ruoyi/common/core/annotation/Excel.java | 5 +++++ .../src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java | 3 +++ 2 files changed, 8 insertions(+) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java index fa7f6eb..f6d4cd2 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/annotation/Excel.java @@ -15,6 +15,11 @@ import java.lang.annotation.Target; public @interface Excel { /** + * 导出时在excel中排序 + */ + public int sort() default Integer.MAX_VALUE; + + /** * 导出到Excel中的名字. */ public String name() default ""; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java index fbfd1dd..783aa8e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java @@ -9,10 +9,12 @@ 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.stream.Collectors; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.ss.usermodel.BorderStyle; @@ -739,6 +741,7 @@ public class ExcelUtil } } } + this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList()); } /**