Bläddra i källkod

清表图片问题

zhuwei 2 år sedan
förälder
incheckning
c16b6e2694

+ 39 - 19
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import com.spire.xls.*;
+import com.spire.xls.collections.PicturesCollection;
 import com.spire.xls.core.spreadsheet.HTMLOptions;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
@@ -284,8 +285,7 @@ public class ExcelTabController extends BladeController {
     })
     public R putFileAttach(@RequestParam("file") MultipartFile file, Long nodeId) {
 
-        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
-        //String file_path = "/Users/hongchuangyanfa/Desktop/";
+        String file_path = FileUtils.getSysLocalFileUrl();
 
         ExcelTab detail = excelTabService.getById(nodeId);
         // 上传excel文件
@@ -302,8 +302,6 @@ public class ExcelTabController extends BladeController {
         //获取工作表
         Worksheet sheet = wb.getWorksheets().get(0);
         sheet.saveToHtml(thmlUrl, options);
-
-//        detail.setExtension(bladeFile1.getOriginalName());
         detail.setExtension(file.getOriginalFilename());
         detail.setFileUrl(bladeFile1.getLink());
         detail.setFileType(3); // 表示为清表信息  1 表示祖节点  2 表示为节点信息 3 表示清表
@@ -625,15 +623,7 @@ public class ExcelTabController extends BladeController {
         }
 
         String fileUrl = wbsTreeContract.getHtmlUrl();
-        File file1 = ResourceUtil.getFile(fileUrl);
-        InputStream fileInputStream = null;
-        if (file1.exists()) {
-            fileInputStream = new FileInputStream(file1);
-        } else {
-            String path = sys_file_net_url + fileUrl.replaceAll("//", "/").replaceAll(file_path, "");
-            fileInputStream = CommonUtil.getOSSInputStream(path);
-        }
-
+        InputStream fileInputStream = FileUtils.getInputStreamByUrl(fileUrl);
         String htmlString = IoUtil.readToString(fileInputStream);
         htmlString = htmlString.replaceAll("placeholder", "placeholderxx");
         htmlString = htmlString.replaceAll("title", "titlexx");
@@ -667,7 +657,7 @@ public class ExcelTabController extends BladeController {
                 String style = data.attr("style");
                 if (style.indexOf("font-size") >= 0) {
                     int fontsize = Integer.parseInt(style.substring(style.indexOf("font-size:") + 10, style.indexOf(".0pt")));
-                    if (StringUtils.isNotEmpty(data.text()) && fontsize >= 12) {
+                    if (StringUtils.isNotEmpty(data.text()) && fontsize >= 14) {
                         trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
                     }
                 }
@@ -829,7 +819,7 @@ public class ExcelTabController extends BladeController {
 
 
     // 上传解析 html
-    public void expailHtmlInfo(String thmlUrl, Long excelId) throws FileNotFoundException {
+    public void expailHtmlInfo(String thmlUrl, Long excelId) throws Exception {
 
         // 读取
         File file1 = ResourceUtil.getFile(thmlUrl);
@@ -853,12 +843,8 @@ public class ExcelTabController extends BladeController {
 
         // 获取图片信息
         Elements imgs = doc.select("img");
-        int imgIndex = 0;
 
 
-        // 移除图片
-        doc.select("img").remove();
-
         // 获取总行列数
         int maxCol = doc.select("Col").size();
         String[] rowData = new String[trs.size() + 5]; //本来加一的 害怕出现特殊情况 故意 加 5
@@ -1267,6 +1253,40 @@ public class ExcelTabController extends BladeController {
         }
         exctabCellService.saveBatch(colTitle2);
 
+
+        //对excel 的图片进行操作
+        ExcelTab exceltab = excelTabService.getById(excelId);
+        if(exceltab!=null){
+            // 获取excle 的数据
+            String fileUrl = exceltab.getFileUrl();
+            InputStream ossInputStream = CommonUtil.getOSSInputStream(fileUrl);
+            Workbook wb = new Workbook();
+            wb.loadFromMHtml(ossInputStream);
+            Worksheet sheet = wb.getWorksheets().get(0);
+            PicturesCollection pictures = sheet.getPictures();
+            if(pictures!=null && pictures.size()>=1){
+                for (int i=0 ; i<pictures.size() ; i++){
+                    ExcelPicture pic = pictures.get(i);
+                    int x = pic.getLeftColumn();
+                    int y = pic.getBottomRow();
+                    Elements select = doc.select("el-input[x1=" + x + "][y1=" + y + "]");
+                    System.out.println("xx=--"+x);
+                    System.out.println("yy=--"+y);
+                    if(select!=null && select.size()>=1){
+                        Element element = select.get(0);
+                        Element elementP = element.parent();
+                        element.remove();
+                        Element imgele = imgs.get(i);
+                        imgele.removeAttr("class");
+                        elementP.append(imgele.toString());
+                    }
+                }
+            }
+
+            ossInputStream.close();
+        }
+        // 移除图片
+        imgs.remove();
         // 保存
         File writefile = new File(thmlUrl);
         FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));

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

@@ -1491,7 +1491,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                             if(StringUtils.isNotEmpty(dataJson)){
                                                 JSONArray jsonArray = JSONArray.parseArray(dataJson);
                                                 List<Integer> idList = Func.toIntList(myData);
-                                                String dataInfo = jsonArray.getJSONObject(0).getString("name");
+                                                String dataInfo = jsonArray.getJSONObject(idList.get(0)).getString("name");
                                                 for(int inx=1 ; inx<idList.size() ; inx++){
                                                     dataInfo = dataInfo+","+jsonArray.getJSONObject(inx).getString("name");
                                                 }