From 29d3490e983cadd2b2107486214488e382a72fcc Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期日, 14 十二月 2025 22:21:33 +0800
Subject: [PATCH] 修改了对应代码
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java | 63 +++++++---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java | 12 +
archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoLarge.java | 51 ++++----
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java | 61 ++++++---
ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java | 5
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java | 2
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java | 53 +++++---
ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java | 6 +
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetThird.java | 59 ++++++---
archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVo.java | 18 +-
10 files changed, 211 insertions(+), 119 deletions(-)
diff --git a/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVo.java b/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVo.java
index b81779c..d9f57ba 100644
--- a/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVo.java
+++ b/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVo.java
@@ -10,30 +10,30 @@
public class DocumentMaterialsVo {
- @Excel(name="搴忓彿")
+ @Excel(name="搴忓彿", height = 10,width=10)
private Long num;
- @Excel(name = "鏂囦欢缂栧彿")
+ @Excel(name = "鏂囦欢缂栧彿", height = 10, width=15)
private String documentNumber;
- @Excel(name = "缂栦换鑰�")
+ @Excel(name = "璐d换鑰�", height = 10, width=10)
private String creator;
- @Excel(name = "鏂囦欢棰樺悕")
+ @Excel(name = "鏂囦欢棰樺悕", height = 20)
private String title;
@JsonFormat(pattern = "yyyy-MM-dd")
- @Excel(name = "鏃ユ湡", width = 30, dateFormat = "yyyy-MM-dd")
+ @Excel(name = "鏃ユ湡", width = 10, dateFormat = "yyyy-MM-dd", height = 10)
private Date date;
- @Excel(name = "椤靛彿")
+ @Excel(name = "椤靛彿", height = 10,width = 10)
private Long pageNumber;
- @Excel(name = "澶囨敞")
+ @Excel(name = "澶囨敞", height = 20)
private String remarks;
- @Excel(name = "妗e彿")
+ @Excel(name = "妗e彿", height = 10)
private String recordId;
- @Excel(name = "鍏紑灞炴��")
+ @Excel(name = "鍏紑灞炴��", height = 10)
private String publicity;
diff --git a/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoLarge.java b/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoLarge.java
index 594b4cd..f0a07d1 100644
--- a/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoLarge.java
+++ b/archiveManager/src/main/java/com/ruoyi/domain/vo/DocumentMaterialsVoLarge.java
@@ -4,6 +4,7 @@
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.annotation.NumberFormatHandler;
import lombok.Data;
+import org.apache.poi.ss.usermodel.IndexedColors;
import java.util.Date;
@@ -217,49 +218,49 @@
this.title = title;
}
- @Excel(name="搴忓彿")
+ @Excel(name="搴忓彿", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private int num;
- @Excel(name="妗e彿")
+ @Excel(name="妗e彿",headerColor = IndexedColors.RED,width = 15, headerBackgroundColor = IndexedColors.WHITE)
private String recordId;
- @Excel(name = "鏂囦欢鏉愭枡搴忓彿", handler = NumberFormatHandler.class)
+ @Excel(name = "鏂囦欢鏉愭枡搴忓彿", width=10,headerColor = IndexedColors.RED,handler = NumberFormatHandler.class, headerBackgroundColor = IndexedColors.WHITE)
private Long fileNumber;
- @Excel(name = "鏂囦欢缂栧彿")
+ @Excel(name = "鏂囦欢缂栧彿",width=9,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE)
private String documentNumber;
/** $column.columnComment */
- @Excel(name = "缂栦换鑰�")
+ @Excel(name = "璐d换鑰�",width=8,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE)
private String creator;
/** $column.columnComment */
- @Excel(name = "鏂囦欢棰樺悕")
+ @Excel(name = "鏂囦欢棰樺悕",headerColor = IndexedColors.RED, headerBackgroundColor = IndexedColors.WHITE)
private String title;
/** $column.columnComment */
@JsonFormat(pattern = "yyyy-MM-dd")
- @Excel(name = "鏃ユ湡", width = 30, dateFormat = "yyyy-MM-dd")
+ @Excel(name = "鏃ユ湡", width = 10, headerColor = IndexedColors.BLACK,dateFormat = "yyyy-MM-dd", headerBackgroundColor = IndexedColors.WHITE)
private Date date;
/** $column.columnComment */
- @Excel(name = "椤靛彿", handler = NumberFormatHandler.class)
+ @Excel(name = "椤靛彿", width = 10,headerColor = IndexedColors.RED,handler = NumberFormatHandler.class, headerBackgroundColor = IndexedColors.WHITE)
private Long pageNumber;
/** $column.columnComment */
- @Excel(name = "椤垫")
+ @Excel(name = "椤垫", width = 10,headerColor = IndexedColors.RED, headerBackgroundColor = IndexedColors.WHITE)
private Long pageOrder;
/** $column.columnComment */
- @Excel(name = "鎵�澶勯樁娈�")
+ @Excel(name = "鎵�澶勯樁娈�", width = 10,headerColor = IndexedColors.RED, headerBackgroundColor = IndexedColors.WHITE)
private String stage;
/** $column.columnComment */
- @Excel(name = "鍏紑灞炴��")
+ @Excel(name = "鍏紑灞炴��", width = 10,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE)
private String publicity;
/** $column.columnComment */
- @Excel(name = "鏄惁涓洪檮浠堕檮鍥�")
+ @Excel(name = "鏄惁涓洪檮浠堕檮鍥�", width = 10,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE)
private String isAttachment;
/** $column.columnComment */
@@ -267,55 +268,55 @@
private String isDiagram;
/** $column.columnComment */
- @Excel(name = "淇濈鏈熼檺")
+ @Excel(name = "淇濈鏈熼檺", width = 10,headerColor = IndexedColors.BLACK, headerBackgroundColor = IndexedColors.WHITE)
private String retentionPeriod;
/** $column.columnComment */
- @Excel(name = "瀵嗙骇", readConverterExp = "璇ラ〉鍙﹀瓨=鏅��,鏅��=鏅��,鍐呴儴鐢ㄥ浘=鍐呴儴鐢ㄥ浘,鍐呴儴鐢ㄩ��=鍐呴儴鐢ㄩ��,绉樺瘑=绉樺瘑")
+ @Excel(name = "瀵嗙骇", width = 10,headerColor = IndexedColors.BLACK,readConverterExp = "璇ラ〉鍙﹀瓨=鏅��,鏅��=鏅��,鍐呴儴鐢ㄥ浘=鍐呴儴鐢ㄥ浘,鍐呴儴鐢ㄩ��=鍐呴儴鐢ㄩ��,绉樺瘑=绉樺瘑", headerBackgroundColor = IndexedColors.WHITE)
private String securityLevel;
/** $column.columnComment */
- @Excel(name = "鏄惁娑夊瘑鍙婃晱鎰熶俊鎭�")
+ @Excel(name = "鏄惁娑夊瘑鍙婃晱鎰熶俊鎭�",headerColor = IndexedColors.BLACK, width = 10, headerBackgroundColor = IndexedColors.WHITE)
private String isSensitive;
/** $column.columnComment */
- @Excel(name = "鏄惁娉ㄩ攢")
+ @Excel(name = "鏄惁娉ㄩ攢" ,headerColor = IndexedColors.BLACK,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private String isCanceled;
/** $column.columnComment */
- @Excel(name = "鏍煎紡")
+ @Excel(name = "鏍煎紡",headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private String format;
/** $column.columnComment */
- @Excel(name = "骞呴潰")
+ @Excel(name = "骞呴潰", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private String sizeType;
/** $column.columnComment */
- @Excel(name = "姘村钩鍒嗚鲸鐜�")
+ @Excel(name = "姘村钩鍒嗚鲸鐜�",headerColor = IndexedColors.RED, width = 10, headerBackgroundColor = IndexedColors.WHITE)
private Long horizontalResolution;
/** $column.columnComment */
- @Excel(name = "鍨傜洿鍒嗚鲸鐜�")
+ @Excel(name = "鍨傜洿鍒嗚鲸鐜�",headerColor = IndexedColors.RED, width = 10, headerBackgroundColor = IndexedColors.WHITE)
private Long verticalResolution;
/** $column.columnComment */
- @Excel(name = "瀹藉害")
+ @Excel(name = "瀹藉害", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private Long width;
/** $column.columnComment */
- @Excel(name = "楂樺害")
+ @Excel(name = "楂樺害", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private Long height;
/** $column.columnComment */
- @Excel(name = "澶у皬")
+ @Excel(name = "澶у皬", headerColor = IndexedColors.RED,width = 10, headerBackgroundColor = IndexedColors.WHITE)
private Double fileSize;
/** $column.columnComment */
- @Excel(name = "闄勪欢鍙婂巻鍙插彂鏂囧彿")
+ @Excel(name = "闄勪欢鍙婂巻鍙插彂鏂囧彿",headerColor = IndexedColors.BLACK, width = 10, headerBackgroundColor = IndexedColors.WHITE)
private String attachmentHistoryNumbers;
/** $column.columnComment */
- @Excel(name = "澶囨敞")
+ //@Excel(name = "澶囨敞", width = 10)
private String remarks;
public String getUrl() {
return url;
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
index f2e7b9a..d3b1239 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/archive/archiveAllExportController.java
@@ -235,6 +235,7 @@
for(int i = 0; i < ids.length; i++) {
+
// 鑾峰彇鏂囦欢鐨勪繚瀛樹綅缃�,璇诲彇鏁版嵁搴�,
DocumentMaterials documentMaterials = new DocumentMaterials();
documentMaterials.setRecordId(ids[i]);
@@ -247,7 +248,7 @@
ArchiveInfoVo aIV = iArchiveRecordsService.selectByRecordId(ids[i]);
String adir = aIV.getInquiryNumber() + " " + aIV.getRecordId();
- System.out.println(fna + adir);
+ System.out.println(fna+adir);
zos.putNextEntry(new ZipEntry(fna + adir + "/"));
//鍦ㄩ噷闈㈡坊鍔犳枃浠�
@@ -531,6 +532,8 @@
System.out.println(filePath+"0009999999999");
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
+ // response.addHeader("Content-Disposition", "attachment;filename=fileName" + ".xls");
+
FileUtils.writeBytes(filePath, response.getOutputStream());
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
index 765d8e3..7f951ad 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
@@ -86,7 +86,7 @@
/**
* 鏄惁鍏佽鍐呭鎹㈣
*/
- public boolean wrapText() default false;
+ public boolean wrapText() default true;
/**
* 璁剧疆鍙兘閫夋嫨涓嶈兘杈撳叆鐨勫垪鍐呭.
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java
index 1f27265..79ba4c7 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java
@@ -221,6 +221,12 @@
.append("utf-8''")
.append(percentEncodedFileName);
+
+ response.setCharacterEncoding("UTF-8");
+ response.setHeader("content-Type", "application/vnd.ms-excel");
+ response.setHeader("Content-Disposition",
+ "attachment;filename=" + URLEncoder.encode(realFileName, "UTF-8"));
+// response.addHeader("Content-Disposition", "attachment;filename=fileName" + ".xls");
response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
response.setHeader("Content-disposition", contentDispositionValue.toString());
response.setHeader("download-filename", percentEncodedFileName);
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
index 726f14b..3abe6b0 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
@@ -912,10 +912,12 @@
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setFillForegroundColor(excel.headerBackgroundColor().index);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ // 璁剧疆琛ㄥご鑷姩鎹㈣
+ style.setWrapText(true);
Font headerFont = wb.createFont();
headerFont.setFontName("Arial");
headerFont.setFontHeightInPoints((short) 10);
- headerFont.setBold(true);
+ headerFont.setBold(false);
headerFont.setColor(excel.headerColor().index);
style.setFont(headerFont);
// 璁剧疆琛ㄦ牸澶村崟鍏冩牸鏂囨湰褰㈠紡
@@ -1054,7 +1056,7 @@
}
else if (ColumnType.IMAGE == attr.cellType())
{
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1);
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), cell.getRow().getRowNum() + 1);
String propertyValue = Convert.toStr(value);
if (StringUtils.isNotEmpty(propertyValue))
{
@@ -1145,8 +1147,8 @@
Cell cell = null;
try
{
- // 璁剧疆琛岄珮
- row.setHeight(maxHeight);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
if (attr.isExport())
{
@@ -1658,7 +1660,7 @@
*/
public void createWorkbook()
{
- this.wb = new SXSSFWorkbook(500);
+ this.wb = new HSSFWorkbook();
this.sheet = wb.createSheet();
wb.setSheetName(0, sheetName);
this.styles = createStyles(wb);
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
index 2415462..62fdb18 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheet.java
@@ -17,9 +17,12 @@
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
-import org.apache.poi.xssf.usermodel.XSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -301,7 +304,7 @@
// if (Files.exists(Paths.get(imagePath))) {
// byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath));
// 灏哹yte鏁扮粍杞崲鎴恑nputstream锛屼互渚挎彃鍏ュ埌Excel涓�
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 5),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 5),
cell.getRow().getRowNum() + 1);
// 璁$畻灞呬腑浣嶇疆
int col1 = 1; // 涓棿鍒�
@@ -497,6 +500,8 @@
style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderBottom(BorderStyle.THIN);
style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
+ // 璁剧疆鑷姩鎹㈣
+ style.setWrapText(true);
Font dataFont = wb.createFont();
dataFont.setFontName("Arial");
dataFont.setFontHeightInPoints((short) 10);
@@ -515,6 +520,8 @@
headerFont.setBold(true);
headerFont.setColor(IndexedColors.WHITE.getIndex());
style.setFont(headerFont);
+ // 琛ㄥご涔熻缃嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("header", style);
style = wb.createCellStyle();
@@ -524,21 +531,29 @@
totalFont.setFontName("Arial");
totalFont.setFontHeightInPoints((short) 10);
style.setFont(totalFont);
+ // 鎬昏琛屼篃璁剧疆鑷姩鎹㈣
+ style.setWrapText(true);
styles.put("total", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.LEFT);
+ // 宸﹀榻愭牱寮忎篃璁剧疆鑷姩鎹㈣
+ style.setWrapText(true);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
+ // 灞呬腑瀵归綈鏍峰紡涔熻缃嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.RIGHT);
+ // 鍙冲榻愭牱寮忎篃璁剧疆鑷姩鎹㈣
+ style.setWrapText(true);
styles.put("data3", style);
return styles;
@@ -570,7 +585,7 @@
} else if (Excel.ColumnType.NUMERIC == attr.cellType()) {
cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
} else if (Excel.ColumnType.IMAGE == attr.cellType()) {
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
String imagePath = Convert.toStr(value);
if (StringUtils.isNotEmpty(imagePath)) {
@@ -617,12 +632,12 @@
// 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀�.
if (StringUtils.isNotEmpty(attr.prompt())) {
// 杩欓噷榛樿璁句簡2-101鍒楁彁绀�.
- setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
+ setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
}
// 濡傛灉璁剧疆浜哻ombo灞炴�у垯鏈垪鍙兘閫夋嫨涓嶈兘杈撳叆
if (attr.combo().length > 0) {
// 杩欓噷榛樿璁句簡2-101鍒楀彧鑳介�夋嫨涓嶈兘杈撳叆.
- setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
+ setHSSFValidation(sheet, attr.combo(), 1, 100, column, column);
}
}
@@ -632,15 +647,23 @@
public Cell addCell(Excel attr, Row row, T vo, Field field, int column) {
Cell cell = null;
try {
- // 璁剧疆琛岄珮
- row.setHeight(maxHeight);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
if (attr.isExport()) {
// 鍒涘缓cell
cell = row.createCell(column);
-// attr.align();
-// int align = attr.align().value;
-// cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
+ // 璁剧疆鍗曞厓鏍兼牱寮�
+ HorizontalAlignment align = attr.align();
+ String styleKey = "data";
+ if (align == HorizontalAlignment.LEFT) {
+ styleKey = "data1";
+ } else if (align == HorizontalAlignment.CENTER) {
+ styleKey = "data2";
+ } else if (align == HorizontalAlignment.RIGHT) {
+ styleKey = "data3";
+ }
+ cell.setCellStyle(styles.get(styleKey));
// 鐢ㄤ簬璇诲彇瀵硅薄涓殑灞炴��
Object value = getTargetValue(vo, field, attr);
@@ -666,7 +689,7 @@
}
/**
- * 璁剧疆 POI XSSFSheet 鍗曞厓鏍兼彁绀�
+ * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
*
* @param sheet 琛ㄥ崟
* @param promptTitle 鎻愮ず鏍囬
@@ -676,7 +699,7 @@
* @param firstCol 寮�濮嬪垪
* @param endCol 缁撴潫鍒�
*/
- public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
+ public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
@@ -698,7 +721,7 @@
* @param endCol 缁撴潫鍒�
* @return 璁剧疆濂界殑sheet.
*/
- public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
+ public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
// 鍔犺浇涓嬫媺鍒楄〃鍐呭
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
@@ -707,11 +730,9 @@
// 鏁版嵁鏈夋晥鎬у璞�
DataValidation dataValidation = helper.createValidation(constraint, regions);
// 澶勭悊Excel鍏煎鎬ч棶棰�
- if (dataValidation instanceof XSSFDataValidation) {
- dataValidation.setSuppressDropDownArrow(true);
- dataValidation.setShowErrorBox(true);
- } else {
+ if (dataValidation instanceof HSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(false);
+ dataValidation.setShowErrorBox(true);
}
sheet.addValidationData(dataValidation);
@@ -908,7 +929,7 @@
* 鍒涘缓涓�涓伐浣滅翱
*/
public void createWorkbook() {
- this.wb = new SXSSFWorkbook(500);
+ this.wb = new HSSFWorkbook();
}
/**
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
index 96852e9..90f7cc9 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetFour.java
@@ -15,9 +15,14 @@
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
-import org.apache.poi.xssf.usermodel.XSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -302,7 +307,7 @@
Cell cell = row.createCell(6);
// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
cell.getRow().getRowNum() + 1);
// 璁$畻灞呬腑浣嶇疆
// int col1 = 0; // 涓棿鍒�
@@ -533,6 +538,8 @@
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(BorderStyle.THIN);
@@ -551,6 +558,8 @@
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
@@ -564,6 +573,8 @@
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
Font totalFont = wb.createFont();
totalFont.setFontName("Arial");
totalFont.setFontHeightInPoints((short) 10);
@@ -573,16 +584,22 @@
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.LEFT);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.RIGHT);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data3", style);
return styles;
@@ -614,7 +631,7 @@
} else if (Excel.ColumnType.NUMERIC == attr.cellType()) {
cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
} else if (Excel.ColumnType.IMAGE == attr.cellType()) {
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
String imagePath = Convert.toStr(value);
if (StringUtils.isNotEmpty(imagePath)) {
@@ -661,12 +678,12 @@
// 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀�.
if (StringUtils.isNotEmpty(attr.prompt())) {
// 杩欓噷榛樿璁句簡2-101鍒楁彁绀�.
- setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
+ setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
}
// 濡傛灉璁剧疆浜哻ombo灞炴�у垯鏈垪鍙兘閫夋嫨涓嶈兘杈撳叆
if (attr.combo().length > 0) {
// 杩欓噷榛樿璁句簡2-101鍒楀彧鑳介�夋嫨涓嶈兘杈撳叆.
- setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
+ setHSSFValidation(sheet, attr.combo(), 1, 100, column, column);
}
}
@@ -676,15 +693,23 @@
public Cell addCell(Excel attr, Row row, T vo, Field field, int column) {
Cell cell = null;
try {
- // 璁剧疆琛岄珮
- row.setHeight(maxHeight);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
if (attr.isExport()) {
// 鍒涘缓cell
cell = row.createCell(column);
-// attr.align();
-// int align = attr.align().value;
-// cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
+ // 璁剧疆鍗曞厓鏍兼牱寮�
+ HorizontalAlignment align = attr.align();
+ String styleKey = "data";
+ if (align == HorizontalAlignment.LEFT) {
+ styleKey = "data1";
+ } else if (align == HorizontalAlignment.CENTER) {
+ styleKey = "data2";
+ } else if (align == HorizontalAlignment.RIGHT) {
+ styleKey = "data3";
+ }
+ cell.setCellStyle(styles.get(styleKey));
// 鐢ㄤ簬璇诲彇瀵硅薄涓殑灞炴��
Object value = getTargetValue(vo, field, attr);
@@ -710,7 +735,7 @@
}
/**
- * 璁剧疆 POI XSSFSheet 鍗曞厓鏍兼彁绀�
+ * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
*
* @param sheet 琛ㄥ崟
* @param promptTitle 鎻愮ず鏍囬
@@ -720,7 +745,7 @@
* @param firstCol 寮�濮嬪垪
* @param endCol 缁撴潫鍒�
*/
- public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
+ public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
@@ -742,7 +767,7 @@
* @param endCol 缁撴潫鍒�
* @return 璁剧疆濂界殑sheet.
*/
- public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
+ public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
// 鍔犺浇涓嬫媺鍒楄〃鍐呭
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
@@ -751,11 +776,9 @@
// 鏁版嵁鏈夋晥鎬у璞�
DataValidation dataValidation = helper.createValidation(constraint, regions);
// 澶勭悊Excel鍏煎鎬ч棶棰�
- if (dataValidation instanceof XSSFDataValidation) {
- dataValidation.setSuppressDropDownArrow(true);
- dataValidation.setShowErrorBox(true);
- } else {
+ if (dataValidation instanceof HSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(false);
+ dataValidation.setShowErrorBox(true);
}
sheet.addValidationData(dataValidation);
@@ -952,7 +975,7 @@
* 鍒涘缓涓�涓伐浣滅翱
*/
public void createWorkbook() {
- this.wb = new SXSSFWorkbook(500);
+ this.wb = new HSSFWorkbook();
}
/**
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
index 2dc3859..a2bcb03 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java
@@ -16,9 +16,12 @@
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
-import org.apache.poi.xssf.usermodel.XSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -299,7 +302,7 @@
//sheet.setColumnWidth(1, 15 * 256); // 绗簩鍒楀搴�15瀛楃
//sheet.setColumnWidth(2, 25 * 256); // 绗笁鍒楀搴�25瀛楃 // 璁剧疆绗竴鍒楀搴︿负20涓瓧绗�
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell.getColumnIndex()+1), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() +2),
cell.getRow().getRowNum() + 1);
// 璁$畻灞呬腑浣嶇疆
// int col1 = 0; // 涓棿鍒�
@@ -379,7 +382,7 @@
Font font = wb.createFont();
font.setBold(true);
style.setFont(font);
-style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+ style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
cell.setCellStyle(style);
cell.setCellValue(tits[i]);
Cell cel = row.createCell(1);
@@ -394,6 +397,8 @@
if(i==3)
{
row = sheet.createRow(8);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// row.setHeight((short) 30);
row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
row = sheet.createRow(9);
@@ -403,7 +408,7 @@
//sheet.setColumnWidth(1, 15 * 256); // 绗簩鍒楀搴�15瀛楃
//sheet.setColumnWidth(2, 25 * 256); // 绗笁鍒楀搴�25瀛楃 // 璁剧疆绗竴鍒楀搴︿负20涓瓧绗�
- ClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, (short) (cell1.getColumnIndex()), cell1.getRow().getRowNum(), (short) (cell1.getColumnIndex() +2),
+ ClientAnchor anchor1 = new HSSFClientAnchor(0, 0, 0, 0, (short) (cell1.getColumnIndex()), cell1.getRow().getRowNum(), (short) (cell1.getColumnIndex() +2),
cell1.getRow().getRowNum() + 1);
// 璁$畻灞呬腑浣嶇疆
//// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
@@ -583,6 +588,8 @@
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(BorderStyle.THIN);
@@ -601,6 +608,8 @@
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
@@ -614,6 +623,8 @@
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
Font totalFont = wb.createFont();
totalFont.setFontName("Arial");
totalFont.setFontHeightInPoints((short) 10);
@@ -623,16 +634,22 @@
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.LEFT);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.RIGHT);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data3", style);
return styles;
@@ -664,7 +681,7 @@
} else if (Excel.ColumnType.NUMERIC == attr.cellType()) {
cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
} else if (Excel.ColumnType.IMAGE == attr.cellType()) {
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
String imagePath = Convert.toStr(value);
if (StringUtils.isNotEmpty(imagePath)) {
@@ -711,12 +728,12 @@
// 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀�.
if (StringUtils.isNotEmpty(attr.prompt())) {
// 杩欓噷榛樿璁句簡2-101鍒楁彁绀�.
- setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
+ setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
}
// 濡傛灉璁剧疆浜哻ombo灞炴�у垯鏈垪鍙兘閫夋嫨涓嶈兘杈撳叆
if (attr.combo().length > 0) {
// 杩欓噷榛樿璁句簡2-101鍒楀彧鑳介�夋嫨涓嶈兘杈撳叆.
- setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
+ setHSSFValidation(sheet, attr.combo(), 1, 100, column, column);
}
}
@@ -726,8 +743,8 @@
public Cell addCell(Excel attr, Row row, T vo, Field field, int column) {
Cell cell = null;
try {
- // 璁剧疆琛岄珮
- row.setHeight((short) 2000);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
if (attr.isExport()) {
// 鍒涘缓cell
@@ -775,7 +792,7 @@
}
/**
- * 璁剧疆 POI XSSFSheet 鍗曞厓鏍兼彁绀�
+ * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
*
* @param sheet 琛ㄥ崟
* @param promptTitle 鎻愮ず鏍囬
@@ -785,7 +802,7 @@
* @param firstCol 寮�濮嬪垪
* @param endCol 缁撴潫鍒�
*/
- public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
+ public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
@@ -807,7 +824,7 @@
* @param endCol 缁撴潫鍒�
* @return 璁剧疆濂界殑sheet.
*/
- public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
+ public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
// 鍔犺浇涓嬫媺鍒楄〃鍐呭
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
@@ -816,11 +833,9 @@
// 鏁版嵁鏈夋晥鎬у璞�
DataValidation dataValidation = helper.createValidation(constraint, regions);
// 澶勭悊Excel鍏煎鎬ч棶棰�
- if (dataValidation instanceof XSSFDataValidation) {
- dataValidation.setSuppressDropDownArrow(true);
- dataValidation.setShowErrorBox(true);
- } else {
+ if (dataValidation instanceof HSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(false);
+ dataValidation.setShowErrorBox(true);
}
sheet.addValidationData(dataValidation);
@@ -1017,7 +1032,7 @@
* 鍒涘缓涓�涓伐浣滅翱
*/
public void createWorkbook() {
- this.wb = new SXSSFWorkbook(500);
+ this.wb = new HSSFWorkbook();
}
/**
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetThird.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetThird.java
index 69ab2f7..6583feb 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetThird.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetThird.java
@@ -16,9 +16,12 @@
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
-import org.apache.poi.xssf.streaming.SXSSFWorkbook;
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
-import org.apache.poi.xssf.usermodel.XSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
+import org.apache.poi.hssf.usermodel.HSSFDataValidation;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -450,6 +453,8 @@
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
style.setBorderRight(BorderStyle.THIN);
style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setBorderLeft(BorderStyle.THIN);
@@ -468,6 +473,8 @@
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
Font headerFont = wb.createFont();
@@ -481,6 +488,8 @@
style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
Font totalFont = wb.createFont();
totalFont.setFontName("Arial");
totalFont.setFontHeightInPoints((short) 10);
@@ -490,16 +499,22 @@
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.LEFT);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data1", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data2", style);
style = wb.createCellStyle();
style.cloneStyleFrom(styles.get("data"));
style.setAlignment(HorizontalAlignment.RIGHT);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
styles.put("data3", style);
return styles;
@@ -531,7 +546,7 @@
} else if (Excel.ColumnType.NUMERIC == attr.cellType()) {
cell.setCellValue(StringUtils.contains(Convert.toStr(value), ".") ? Convert.toDouble(value) : Convert.toInt(value));
} else if (Excel.ColumnType.IMAGE == attr.cellType()) {
- ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
+ ClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
String imagePath = Convert.toStr(value);
if (StringUtils.isNotEmpty(imagePath)) {
@@ -578,12 +593,12 @@
// 濡傛灉璁剧疆浜嗘彁绀轰俊鎭垯榧犳爣鏀句笂鍘绘彁绀�.
if (StringUtils.isNotEmpty(attr.prompt())) {
// 杩欓噷榛樿璁句簡2-101鍒楁彁绀�.
- setXSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
+ setHSSFPrompt(sheet, "", attr.prompt(), 1, 100, column, column);
}
// 濡傛灉璁剧疆浜哻ombo灞炴�у垯鏈垪鍙兘閫夋嫨涓嶈兘杈撳叆
if (attr.combo().length > 0) {
// 杩欓噷榛樿璁句簡2-101鍒楀彧鑳介�夋嫨涓嶈兘杈撳叆.
- setXSSFValidation(sheet, attr.combo(), 1, 100, column, column);
+ setHSSFValidation(sheet, attr.combo(), 1, 100, column, column);
}
}
@@ -593,15 +608,23 @@
public Cell addCell(Excel attr, Row row, T vo, Field field, int column) {
Cell cell = null;
try {
- // 璁剧疆琛岄珮
- row.setHeight(maxHeight);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// 鏍规嵁Excel涓缃儏鍐靛喅瀹氭槸鍚﹀鍑�,鏈変簺鎯呭喌闇�瑕佷繚鎸佷负绌�,甯屾湜鐢ㄦ埛濉啓杩欎竴鍒�.
if (attr.isExport()) {
// 鍒涘缓cell
cell = row.createCell(column);
-// attr.align();
-// int align = attr.align().value;
-// cell.setCellStyle(styles.get("data" + (align >= 1 && align <= 3 ? align : "")));
+ // 璁剧疆鍗曞厓鏍兼牱寮�
+ HorizontalAlignment align = attr.align();
+ String styleKey = "data";
+ if (align == HorizontalAlignment.LEFT) {
+ styleKey = "data1";
+ } else if (align == HorizontalAlignment.CENTER) {
+ styleKey = "data2";
+ } else if (align == HorizontalAlignment.RIGHT) {
+ styleKey = "data3";
+ }
+ cell.setCellStyle(styles.get(styleKey));
// 鐢ㄤ簬璇诲彇瀵硅薄涓殑灞炴��
Object value = getTargetValue(vo, field, attr);
@@ -627,7 +650,7 @@
}
/**
- * 璁剧疆 POI XSSFSheet 鍗曞厓鏍兼彁绀�
+ * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
*
* @param sheet 琛ㄥ崟
* @param promptTitle 鎻愮ず鏍囬
@@ -637,7 +660,7 @@
* @param firstCol 寮�濮嬪垪
* @param endCol 缁撴潫鍒�
*/
- public void setXSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
+ public void setHSSFPrompt(Sheet sheet, String promptTitle, String promptContent, int firstRow, int endRow,
int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
DataValidationConstraint constraint = helper.createCustomConstraint("DD1");
@@ -659,7 +682,7 @@
* @param endCol 缁撴潫鍒�
* @return 璁剧疆濂界殑sheet.
*/
- public void setXSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
+ public void setHSSFValidation(Sheet sheet, String[] textlist, int firstRow, int endRow, int firstCol, int endCol) {
DataValidationHelper helper = sheet.getDataValidationHelper();
// 鍔犺浇涓嬫媺鍒楄〃鍐呭
DataValidationConstraint constraint = helper.createExplicitListConstraint(textlist);
@@ -668,11 +691,9 @@
// 鏁版嵁鏈夋晥鎬у璞�
DataValidation dataValidation = helper.createValidation(constraint, regions);
// 澶勭悊Excel鍏煎鎬ч棶棰�
- if (dataValidation instanceof XSSFDataValidation) {
- dataValidation.setSuppressDropDownArrow(true);
- dataValidation.setShowErrorBox(true);
- } else {
+ if (dataValidation instanceof HSSFDataValidation) {
dataValidation.setSuppressDropDownArrow(false);
+ dataValidation.setShowErrorBox(true);
}
sheet.addValidationData(dataValidation);
@@ -869,7 +890,7 @@
* 鍒涘缓涓�涓伐浣滅翱
*/
public void createWorkbook() {
- this.wb = new SXSSFWorkbook(500);
+ this.wb = new HSSFWorkbook();
}
/**
--
Gitblit v1.9.1