From a5edca4c62ea99418dcaa5d792947b1bab7fe8b2 Mon Sep 17 00:00:00 2001
From: fei <791364011@qq.com>
Date: 星期三, 17 十二月 2025 23:08:36 +0800
Subject: [PATCH] 修改了对应代码
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtilManySheetSecond.java | 139 ++++++++++++++++++++++++----------------------
1 files changed, 73 insertions(+), 66 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 53de95f..aa097a8 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
@@ -302,42 +302,31 @@
//sheet.setColumnWidth(1, 15 * 256); // 绗簩鍒楀搴�15瀛楃
//sheet.setColumnWidth(2, 25 * 256); // 绗笁鍒楀搴�25瀛楃 // 璁剧疆绗竴鍒楀搴︿负20涓瓧绗�
- 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; // 涓棿鍒�
-// 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(120);
+ // 浜岀淮鐮侀渶瑕佽緝澶х殑鍒楀鏉ユ樉绀猴紝璁剧疆涔嬪墠鍏堜繚瀛樺綋鍓嶅垪瀹�
+ int currentColumnWidth = sheet.getColumnWidth(1);
+ // 璁剧疆瓒冲瀹界殑鍒楀浠ユ樉绀轰簩缁寸爜
+ sheet.setColumnWidth(1, 60 * 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);
+ }
@@ -370,9 +359,12 @@
row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�20纾�
// row.createCell(0)
cell = row.createCell(0);
- //璁剧疆cell鐨勫搴�
- sheet.setColumnWidth(0, 20 * 256);
- sheet.setColumnWidth(1, 60 * 256); // 绗簩鍒楀搴�15瀛楃
+ // 鏍规嵁鐢ㄦ埛闇�姹傝缃浜屽瓙琛ㄦ牸鐨勫垪瀹�
+ // 绗竴鍒楀搴﹁缃负27
+ // 绗簩鍒楀搴﹁缃负51
+ // 浣跨敤涓巃ddCell鏂规硶鐩稿悓鐨勮绠楀叕寮忚缃垪瀹�
+ sheet.setColumnWidth(0, (int) ((27 + 0.72) * 256)); // 绗竴鍒楋細瀹藉害27
+ sheet.setColumnWidth(1, (int) ((51 + 0.72) * 256)); // 绗簩鍒楋細瀹藉害51
CellStyle style = wb.createCellStyle();
style.setAlignment(HorizontalAlignment.RIGHT);
@@ -391,7 +383,15 @@
style1.setWrapText(true); // 璁剧疆鑷姩鎹㈣
style1.setVerticalAlignment(VerticalAlignment.CENTER);
cel.setCellStyle(style1);
- cel.setCellValue(fieldValue.toString());
+
+ // 澶勭悊鏃ユ湡鏍煎紡鍖栵紝鐗瑰埆鏄�"缂� 鍒� 鏃� 鏈�:"杩欎竴琛�
+ 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());
+ }
// sheet.setColumnWidth(0, 60 * 256);
i++;
if(i==3)
@@ -403,30 +403,32 @@
row.setHeightInPoints(40); // 璁剧疆琛岄珮涓�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 HSSFClientAnchor(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(70);
+ // 璁剧疆鍒楀瓒冲瀹戒互鏄剧ず鏉″舰鐮侊紝鍏堜繚瀛樺綋鍓嶅垪瀹�
+ int currentColumnWidth0 = sheet.getColumnWidth(0);
+ sheet.setColumnWidth(0, 40 * 256);
+
+ // 鍒涘缓鍥剧墖閿氱偣锛岃缃湪绗�10琛岀1鍒�
+ // 鏉″舰鐮佸眳涓笖涓嶈秴鍑虹浜屼釜鏍煎瓙
+ // 璋冩暣缁撴潫鍒楃储寮曞拰浣嶇疆鍙傛暟
+ // 澧炲姞dx1鍊硷紝浣挎潯褰㈢爜鏁翠綋鍚戝彸绉诲姩
+ ClientAnchor anchor1 = new HSSFClientAnchor(300, 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);
+ }
@@ -765,9 +767,14 @@
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);
@@ -775,7 +782,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); // 璁剧疆鑷姩鎹㈣
--
Gitblit v1.9.1