From f2f1274c7b51671d6d3b0b503f229da4657484f2 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期五, 19 十二月 2025 23:31:58 +0800
Subject: [PATCH] 修改了对应代码
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java | 328 ++++++++++++++++++++++++++++++++++++------------------
1 files changed, 219 insertions(+), 109 deletions(-)
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..65859d0 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
@@ -14,18 +14,18 @@
import com.ruoyi.common.utils.reflect.ReflectUtils;
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.Workbook;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
-import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -34,6 +34,7 @@
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;
+
/**
* Excel鐩稿叧澶勭悊
@@ -57,6 +58,14 @@
* 瀵煎嚭绫诲瀷锛圗XPORT:瀵煎嚭鏁版嵁锛汭MPORT锛氬鍏ユā鏉匡級
*/
private Excel.Type type;
+
+ public Workbook getWb() {
+ return wb;
+ }
+
+ public void setWb(Workbook wb) {
+ this.wb = wb;
+ }
/**
* 宸ヤ綔钖勫璞�
@@ -290,7 +299,7 @@
row = sheet.createRow(0);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 0, 1));
row = sheet.createRow(2);
- row.setHeightInPoints(120); // 璁剧疆琛岄珮涓�20纾�
+ row.setHeightInPoints(100); // 璁剧疆琛岄珮涓�20纾�
//鎷垮埌鍥剧墖
// 鍒涘缓鍗曞厓鏍煎苟娣诲姞鍥剧墖
@@ -299,47 +308,45 @@
//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),
- cell.getRow().getRowNum() + 1);
- // 璁$畻灞呬腑浣嶇疆
-// int col1 = 0; // 涓棿鍒�
-// int col2 = col1 + 2;
-// anchor.setCol1(col1);
-// anchor.setCol2(col2);
-// anchor.setDx1(100);
-// anchor.setDy1(0);
-// anchor.setDx2(255); // 瀹藉害
-// anchor.setDy2(255); // 楂樺害
- anchor.setRow1(2);
- anchor.setRow2(3);
+ // 璁剧疆浜岀淮鐮�
byte[] data = list.get(index).getSedcode();
-// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
- anchor.setDx1(2400000);
- anchor.setDy1(100);
-
- anchor.setDy2(-600000);
- // 鑾峰彇鍥剧墖鍘熷灏哄
- BufferedImage image = ImageIO.read(new ByteArrayInputStream(data));
- double widthInEMU = image.getWidth() * 9525 * 0.2;
- double heightInEMU = image.getHeight() * 9525;
-
- // 璁剧疆鍥剧墖鍘熷灏哄
- anchor.setDx2(-100000); // 鍘熷瀹藉害
- // anchor.setDy2((int)heightInEMU); // 鍘熷楂樺害
-//anchor.setCol1(5); // 浠庣6鍒楀紑濮嬫樉绀�
-//anchor.setCol2(10); // 鍒扮11鍒楃粨鏉�
-
- //Files.readAllBytes(Paths.get(RuoYiConfig.getProfile() + "/upload/2025/08/14/30_20250814212128A031.jpg"));
-//
-//
-// System.out.println(data.length);
- getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
- cell.getSheet().getWorkbook().addPicture(data, getImageType(data)));
+ if (data != null && data.length > 0) {
+ // 鍒涘缓鍗曞厓鏍�
+ Cell qrCell = sheet.createRow(2).createCell(1);
+ // 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず浜岀淮鐮�
+ sheet.getRow(2).setHeightInPoints(100);
+ // 浜岀淮鐮侀渶瑕佽緝澶х殑鍒楀鏉ユ樉绀猴紝璁剧疆涔嬪墠鍏堜繚瀛樺綋鍓嶅垪瀹�
+ int currentColumnWidth = sheet.getColumnWidth(1);
+ // 璁剧疆瓒冲瀹界殑鍒楀浠ユ樉绀轰簩缁寸爜
+ sheet.setColumnWidth(1, 40 * 256);
+
+ // 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�2琛岀2鍒�
+ // 浜岀淮鐮佹樉绀哄湪鍙充笂瑙掍笖涓嶅~婊℃暣涓牸瀛�
+ // 缂╁皬鍥剧墖鑼冨洿锛氬彧鍗犵敤閮ㄥ垎鍗曞厓鏍肩┖闂�
+ ClientAnchor anchor = new HSSFClientAnchor(600, 20, 1000, 200, (short) 1, 2, (short) 1, 2);
+ // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
+ anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
+
+ // 娣诲姞鍥剧墖鍒板伐浣滆〃
+ getDrawingPatriarch(sheet).createPicture(anchor,
+ wb.addPicture(data, getImageType(data)));
+ // 浜岀淮鐮佹坊鍔犲畬鎴愬悗锛屾仮澶嶅師鏉ョ殑鍒楀璁剧疆
+ sheet.setColumnWidth(1, currentColumnWidth);
+ }
- String [] tits = {"妗� 鍙�:","妗f棣�(瀹�)鍙�:","缂� 寰� 鍙�: ","鍙� 鏂� 鍙�:",
- "妗� 鍗� 棰� 鍚�:","缂� 鍒� 鏃� 鏈�:","缂� 鍒� 鍗� 浣�:","淇� 绠� 鏈� 闄�:","瀵� 绾�:"};
+ // 浠�"妗f棣� (瀹�) 鍙�:"涓哄熀鍑嗭紝缁熶竴鎵�鏈夋爣棰樼殑闀垮害鍜屾牸寮�
+ String [] tits = {
+ "妗� 鍙�:",
+ "妗f棣� (瀹�) 鍙�:",
+ "缂� 寰� 鍙�:",
+ "鍙� 鏂� 鍙�:",
+ "妗� 鍗� 棰� 鍚�:",
+ "缂� 鍒� 鏃� 鏈�:",
+ "缂� 鍒� 鍗� 浣�:",
+ "淇� 绠� 鏈� 闄�:",
+ "瀵� 绾�:"};
List tmp = list.get(index).getDataset();
Object obj = tmp.get(0);
@@ -364,64 +371,113 @@
if(i > 3)
row = sheet.createRow(i+7);
// row.setHeight((short) 30);
- row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
- // row.createCell(0)
+ // 涓嶈缃浐瀹氳楂橈紝鍚庣画浣跨敤autoSizeRow鑷姩璋冩暣
cell = row.createCell(0);
- //璁剧疆cell鐨勫搴�
- sheet.setColumnWidth(0, 20 * 256);
- sheet.setColumnWidth(1, 60 * 256); // 绗簩鍒楀搴�15瀛楃
+ // 鏍规嵁鐢ㄦ埛闇�姹傝缃浜屽瓙琛ㄦ牸鐨勫垪瀹�
+ // 绗竴鍒楀搴﹁缃负27
+ // 绗簩鍒楀搴﹁缃负51
+ // 浣跨敤涓巃ddCell鏂规硶鐩稿悓鐨勮绠楀叕寮忚缃垪瀹�
+ sheet.setColumnWidth(0, (int) ((29 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
+ sheet.setColumnWidth(1, (int) ((52 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.RIGHT);
- style.setVerticalAlignment(VerticalAlignment.CENTER);
-style.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
- // style.setAlignment(VerticalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
+ style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+
+ // 璁剧疆瀛椾綋涓篢imes New Roman 18鍙�
Font font = wb.createFont();
font.setBold(true);
+ font.setFontName("Times New Roman");
+ font.setFontHeightInPoints((short) 18);
style.setFont(font);
-style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
+ style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
cell.setCellStyle(style);
cell.setCellValue(tits[i]);
Cell cel = row.createCell(1);
CellStyle style1 = wb.createCellStyle();
style1.setBorderBottom(BorderStyle.THIN); // 娣诲姞涓嬪垝绾�
style1.setWrapText(true); // 璁剧疆鑷姩鎹㈣
- style1.setVerticalAlignment(VerticalAlignment.CENTER);
+ style1.setVerticalAlignment(VerticalAlignment.BOTTOM); // 璁剧疆鍨傜洿涓嬪榻�
+
+ // 璁剧疆鍐呭瀛椾綋涓篢imes New Roman 16鍙�
+ Font contentFont = wb.createFont();
+ contentFont.setFontName("Times New Roman");
+ contentFont.setFontHeightInPoints((short) 16);
+
+ // 褰搃==4鏃讹紝涓烘枃瀛楁坊鍔犱笅鍒掔嚎
+ if(i==4) {
+ contentFont.setUnderline(Font.U_SINGLE); // 娣诲姞鍗曚笅鍒掔嚎
+ }
+
+ style1.setFont(contentFont);
cel.setCellStyle(style1);
- cel.setCellValue(fieldValue.toString());
+ if(i==4)
+ {
+ // 纭繚妗� 鍗� 棰� 鍚�:杩欎竴琛岃兘鏍规嵁鍐呭闀垮害鑷姩鎹㈣
+ style1.setWrapText(true); // 鏄庣‘璁剧疆鑷姩鎹㈣
+ cel.setCellStyle(style1);
+ }
+ // 澶勭悊鏃ユ湡鏍煎紡鍖栵紝鐗瑰埆鏄�"缂� 鍒� 鏃� 鏈�:"杩欎竴琛�
+ if (i == 5 && fieldValue instanceof Date) {
+ // 璁剧疆鏃ユ湡鏍煎紡涓簓yyy-MM-dd
+ String dateStr = DateUtils.parseDateToStr("yyyy-MM-dd", (Date) fieldValue);
+ cel.setCellValue(dateStr);
+ } else {
+ cel.setCellValue(fieldValue.toString());
+ }
+
+ // 瀵逛簬i==4鐨勬儏鍐碉紝纭繚琛岄珮鑳芥牴鎹唴瀹硅嚜鍔ㄨ皟鏁�
+ if(i==4)
+ {
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
+ row.setHeight((short) -1);
+ // 涓嶉檺鍒舵渶澶ц楂橈紝鍏佽鏍规嵁鍐呭鑷姩璋冩暣
+ } else {
+ // 浣跨敤setHeight鏂规硶璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁达紙-1琛ㄧず鑷姩楂樺害锛�
+ row.setHeight((short) -1);
+ // 纭繚琛岄珮鑷冲皯涓�40纾咃紝浣嗕笉闄愬埗鏈�澶ц楂�
+ if (row.getHeightInPoints() < 40) {
+ row.setHeightInPoints(40);
+ }
+ }
// sheet.setColumnWidth(0, 60 * 256);
i++;
if(i==3)
{
row = sheet.createRow(8);
+ // 璁剧疆琛岄珮涓鸿嚜鍔ㄨ皟鏁�
+ row.setHeight((short) -1);
// row.setHeight((short) 30);
- row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
+ row.setHeightInPoints(20); // 璁剧疆琛岄珮涓�20纾�
row = sheet.createRow(9);
//璁剧疆鏉″舰鐮�
- Cell cell1 = row.createCell(0);
-//sheet.setColumnWidth(0, 20 * 256); // 绗竴鍒楀搴�20瀛楃
-//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),
- cell1.getRow().getRowNum() + 1);
- // 璁$畻灞呬腑浣嶇疆
-//// 璁剧疆鍥剧墖澶у皬鍜屼綅缃�
-anchor1.setDx1(600000);
-anchor1.setDy1(0);
-anchor1.setDx2(-600000); // 瀹藉害
-anchor1.setDy2(255); // 楂樺害
-//anchor1.setCol1(0.5); // 浠庣6鍒楀紑濮嬫樉绀�
-//anchor1.setCol2(10); // 鍒扮11鍒楃粨鏉�
- anchor1.setRow1(9);
- anchor1.setRow2(10);
+ // 璁剧疆鏉″舰鐮�
byte[] dat = list.get(index).getImgr();
- //Files.readAllBytes(Paths.get(RuoYiConfig.getProfile() + "/upload/2025/08/14/30_20250814212128A031.jpg"));
-//
-//
-// System.out.println(data.length);
- getDrawingPatriarch(cell1.getSheet()).createPicture(anchor1,
- cell.getSheet().getWorkbook().addPicture(dat, getImageType(dat)));
+ if (dat != null && dat.length > 0) {
+ // 鍒涘缓鍗曞厓鏍�
+ Cell barcodeCell = sheet.createRow(9).createCell(0);
+ // 璁剧疆琛岄珮瓒冲楂樹互鏄剧ず鏉″舰鐮�
+ sheet.getRow(9).setHeightInPoints(40);
+ // 璁剧疆鍒楀瓒冲瀹戒互鏄剧ず鏉″舰鐮侊紝鍏堜繚瀛樺綋鍓嶅垪瀹�
+ int currentColumnWidth0 = sheet.getColumnWidth(0);
+ sheet.setColumnWidth(0, 40 * 256);
+
+ // 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�10琛岀1鍒�
+ // 鏉″舰鐮佸眳涓笖涓嶈秴鍑虹浜屼釜鏍煎瓙
+ // 璋冩暣缁撴潫鍒楃储寮曞拰浣嶇疆鍙傛暟
+ // 澧炲姞dx1鍊硷紝浣挎潯褰㈢爜鏁翠綋鍚戝彸绉诲姩
+ ClientAnchor anchor1 = new HSSFClientAnchor(660, 50, 900, 200, (short) 0, 9, (short) 1, 10);
+ // 璁剧疆鍥剧墖浣嶇疆鍜屽ぇ灏�
+ anchor1.setAnchorType(ClientAnchor.AnchorType.MOVE_DONT_RESIZE);
+
+ // 娣诲姞鍥剧墖鍒板伐浣滆〃
+ getDrawingPatriarch(sheet).createPicture(anchor1,
+ wb.addPicture(dat, getImageType(dat)));
+
+ // 鏉″舰鐮佹坊鍔犲畬鎴愬悗锛屾仮澶嶅師鏉ョ殑鍒楀璁剧疆
+ sheet.setColumnWidth(0, currentColumnWidth0);
+ }
@@ -583,6 +639,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);
@@ -597,23 +655,41 @@
style.setFont(dataFont);
styles.put("data", style);
- style = wb.createCellStyle();
- style.cloneStyleFrom(styles.get("data"));
- style.setAlignment(HorizontalAlignment.CENTER);
- style.setVerticalAlignment(VerticalAlignment.CENTER);
- style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex());
- style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
- Font headerFont = wb.createFont();
- headerFont.setFontName("Arial");
- headerFont.setFontHeightInPoints((short) 10);
- headerFont.setBold(true);
- headerFont.setColor(IndexedColors.WHITE.getIndex());
- style.setFont(headerFont);
- styles.put("header", style);
+ // 鍒涘缓琛ㄥご鏍峰紡鏄犲皠锛屾牴鎹瓻xcel娉ㄨВ鍔ㄦ�佺敓鎴�
+ Map<String, CellStyle> headerStyles = new HashMap<String, CellStyle>();
+ for (Object[] os : fields)
+ {
+ Excel excel = (Excel) os[1];
+ String key = StringUtils.format("header_{}_{}_{}_{}_{}", excel.headerColor(), excel.headerBackgroundColor(), excel.headerFontName(), excel.headerFontBold(), excel.headerFontSize());
+ if (!headerStyles.containsKey(key))
+ {
+ style = wb.createCellStyle();
+ style.cloneStyleFrom(styles.get("data"));
+ style.setAlignment(HorizontalAlignment.CENTER);
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
+ // 璁剧疆鍗曞厓鏍煎唴瀹硅嚜鍔ㄦ崲琛�
+ style.setWrapText(true);
+ // 鏍规嵁娉ㄨВ璁剧疆琛ㄥご鑳屾櫙鑹� - 宸叉敞閲婏紝琛ㄥご涓嶆樉绀鸿儗鏅壊
+ /*if (excel.headerBackgroundColor() != IndexedColors.WHITE) {
+ style.setFillForegroundColor(excel.headerBackgroundColor().index);
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+ }*/
+ Font headerFont = wb.createFont();
+ headerFont.setFontName(excel.headerFontName());
+ headerFont.setFontHeightInPoints((short) excel.headerFontSize()); // 浣跨敤Excel娉ㄨВ涓殑headerFontSize灞炴��
+ headerFont.setBold(excel.headerFontBold());
+ headerFont.setColor(excel.headerColor().index);
+ style.setFont(headerFont);
+ headerStyles.put(key, style);
+ }
+ }
+ styles.putAll(headerStyles);
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 +699,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;
@@ -647,7 +729,9 @@
// 鍐欏叆鍒椾俊鎭�
cell.setCellValue(attr.name());
setDataValidation(attr, row, column);
- cell.setCellStyle(styles.get("header"));
+ // 鏍规嵁Excel娉ㄨВ鍔ㄦ�侀�夋嫨琛ㄥご鏍峰紡
+ String key = StringUtils.format("header_{}_{}_{}_{}_{}", attr.headerColor(), attr.headerBackgroundColor(), attr.headerFontName(), attr.headerFontBold(), attr.headerFontSize());
+ cell.setCellStyle(styles.get(key));
return cell;
}
@@ -664,7 +748,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 +795,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,15 +810,20 @@
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
cell = row.createCell(column);
- //璁剧疆cell鐨勫搴�
- sheet.setColumnWidth(0, 20 * 256);
- sheet.setColumnWidth(1, 60 * 256); // 绗簩鍒楀搴�15瀛楃
+ // 璁剧疆鍒楀锛屼娇鐢ˊExcel娉ㄨВ涓厤缃殑瀹藉害
+ if (column == 0) {
+ // 绗竴鍒椾娇鐢ㄥ浐瀹氬搴�
+ sheet.setColumnWidth(0, 20 * 256);
+ } else if (column == 1) {
+ // 绗簩鍒椾娇鐢ˊExcel娉ㄨВ涓厤缃殑瀹藉害
+ sheet.setColumnWidth(1, (int) ((attr.width() + 0.72) * 256));
+ }
CellStyle style = wb.createCellStyle();
// style.setAlignment(HorizontalAlignment.RIGHT);
@@ -742,7 +831,7 @@
style.setVerticalAlignment(VerticalAlignment.CENTER); // 璁剧疆鍨傜洿灞呬腑
// style.setAlignment(VerticalAlignment.CENTER);
Font font = wb.createFont();
- font.setBold(true);
+ // font.setBold(true);
style.setFont(font);
style.setWrapText(true); // 璁剧疆鑷姩鎹㈣
@@ -775,7 +864,7 @@
}
/**
- * 璁剧疆 POI XSSFSheet 鍗曞厓鏍兼彁绀�
+ * 璁剧疆 POI HSSFSheet 鍗曞厓鏍兼彁绀�
*
* @param sheet 琛ㄥ崟
* @param promptTitle 鎻愮ず鏍囬
@@ -785,7 +874,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 +896,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 +905,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 +1104,7 @@
* 鍒涘缓涓�涓伐浣滅翱
*/
public void createWorkbook() {
- this.wb = new SXSSFWorkbook(500);
+ this.wb = new HSSFWorkbook();
}
/**
@@ -1086,4 +1173,27 @@
}
return val;
}
+
+ /**
+ * 灏咥pache POI鐨刉orkbook杞崲涓篈spose.Cells鐨刉orkbook
+ *
+ * @param poiWorkbook Apache POI鐨刉orkbook瀵硅薄
+ * @return Aspose.Cells鐨刉orkbook瀵硅薄
+ * @throws IOException IO寮傚父
+ */
+
+
+
}
+
+
+
+
+
+
+
+
+
+
+
+
--
Gitblit v1.9.1