Jelajahi Sumber

试验-保存表单
1、处理有图片的情况 pdf上未生成图片

LHB 1 bulan lalu
induk
melakukan
869ffddb82

+ 17 - 19
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -3726,29 +3726,27 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                         }
 
                                         // 特殊处理多选框
-                                        if (myData.contains("http") && myData.contains("aliyuncs")) {
+                                        if (myData.indexOf("http") >= 0 && (myData.indexOf("aliyuncs") >= 0 ||myData.indexOf("183.247.216.148") >= 0||myData.indexOf("xinan1.zos.ctyun.cn") >= 0)) {
                                             InputStream imageIn = CommonUtil.getOSSInputStream(myData);
-                                            byte[] byteNew = new byte[0];
                                             if (imageIn != null) {
-                                                byteNew = IOUtils.toByteArray(imageIn);
+                                                byte[] bytes = CommonUtil.compressImage3(myData);
+                                                // 这里根据实际需求选择图片类型
+                                                int pictureIdx = workbook.addPicture(bytes, 6);
+                                                CreationHelper helper = workbook.getCreationHelper();
+                                                ClientAnchor anchor = helper.createClientAnchor();
+                                                anchor.setCol1(x1); // param1是列号
+                                                anchor.setCol2(x2);
+                                                anchor.setRow1(y1); // param2是行号
+                                                anchor.setRow2(y2); // param2是行号
+                                                //
+                                                Drawing drawing = sheet.createDrawingPatriarch();
+                                                anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
+                                                // 插入图片
+                                                Picture pict = drawing.createPicture(anchor, pictureIdx); // 调整图片占单元格百分比的大小,1.0就是100%
+                                                pict.resize(0.9, 0.9);
+                                                FileUtils.imageOrientation(sheet, anchor, new DataVO(x1 - 1, y1 - 1));
                                             }
 
-                                            byte[] bytes = CommonUtil.compressImage(byteNew);
-
-                                            CreationHelper helper = workbook.getCreationHelper();
-                                            ClientAnchor anchor = helper.createClientAnchor();
-                                            anchor.setCol1(x1); // param1是列号
-                                            anchor.setCol2(x2);
-                                            anchor.setRow1(y1); // param2是行号
-                                            anchor.setRow2(y2); // param2是行号
-
-                                            Drawing<?> drawing = sheet.createDrawingPatriarch();
-                                            anchor.setAnchorType(ClientAnchor.AnchorType.MOVE_AND_RESIZE);
-                                            // 插入图片
-                                            Picture picture = drawing.createPicture(anchor, workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG));
-                                            picture.resize(1, 1);
-                                            FileUtils.imageOrientation(sheet, anchor, new DataVO(x1 - 1, y1 - 1));
-
                                         } else if (myData.equals("1") && data.html().contains("hc-form-checkbox-group")) {
                                             Row row = sheet.getRow(y1 - 1);
                                             if (row != null) {