Forráskód Böngészése

Logo没有也能导出受控文件

baihe 3 éve
szülő
commit
6f304defcb

+ 16 - 12
application-facade/src/main/java/com/factory/web/service/impl/FileServiceImpl.java

@@ -60,11 +60,14 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
         XSSFCellStyle cellStyle = Utility.getTitleCellStyle(wb, (short) 10, HorizontalAlignment.CENTER);
         XSSFCellStyle cellStyleLeft = Utility.getTitleCellStyle(wb, (short) 10, HorizontalAlignment.LEFT);
         FileEntry file = this.getById(Long.parseLong(imgId));
-        ByteArrayInputStream inb = new ByteArrayInputStream(file.getFile());
-        BufferedImage bufferImg = ImageIO.read(inb);
+        BufferedImage bufferImg = null;
+        if(file!=null) {
+        	ByteArrayInputStream inb = new ByteArrayInputStream(file.getFile());
+        	bufferImg = ImageIO.read(inb);
+        	inb.close();
+        }
         String[] data = getOnsiteTitle1Data();
         createOnsiteTitle1(wb, sheet, cellStyle, 0, data, bufferImg);
-        inb.close();
         data = getOnsiteTitle2Data(plan);
         createOnsiteTitle2(sheet, cellStyle, 1, data);
         data = getOnsiteTitle3Data(plan, param, iscontroll);
@@ -370,15 +373,16 @@ public class FileServiceImpl extends ServiceImpl<FileMapper, FileEntry> implemen
         Utility.addCellValForStr(row.getCell(0), data[0], cellStyle);
         Utility.addCellValForStr(row.getCell(3), data[1], Utility.getTitleCellStyle(wb, (short) 15, HorizontalAlignment.CENTER));
         Utility.addCellValForStr(row.getCell(21), data[2], Utility.getTitleCellStyle(wb, (short) 10, HorizontalAlignment.LEFT));
-        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
-        ImageIO.write(bufferImg, "png", byteArrayOut);
-        Drawing patriarch = sheet.createDrawingPatriarch();
-        XSSFClientAnchor anchor = new XSSFClientAnchor(10, 10, 255, 255,
-                (short) 28, 0, (short) 36, 2);
-        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
-                .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));  // 插入图片
-        byteArrayOut.close();
-
+        if(bufferImg!=null) {
+	        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
+	        ImageIO.write(bufferImg, "png", byteArrayOut);
+	        Drawing patriarch = sheet.createDrawingPatriarch();
+	        XSSFClientAnchor anchor = new XSSFClientAnchor(10, 10, 255, 255,
+	                (short) 28, 0, (short) 36, 2);
+	        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut
+	                .toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG));  // 插入图片
+	        byteArrayOut.close();
+        }
 
     }
 }

+ 1 - 1
application-facade/src/main/resources/application.yml

@@ -83,5 +83,5 @@ wx:
     miniprogramState: formal
 download:
   excel:
-    imgid: 23
+    imgid: 1
     companyname: 本特勒汽车系统(沈阳)有限公司